blib/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm

filter: Statementstmt 13.0% 26 / 199 Branchbran 0.0% 0 / 108 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 32.0% 8 / 25 Podpod n/a totaltotal 8.8% 34 / 383 CC 68 SCAR 74.8
CC
68
Cov
8%
_columns_info_for
2963.2
_setup
56.0
_table_fk_info
20.0
CRAP 1777.4
↑ Summary blib/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm »
1 package DBIx::Class::Schema::Loader::DBI::Oracle;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.07053';
12  
13 =head1 NAME
14  
15 DBIx::Class::Schema::Loader::DBI::Oracle - DBIx::Class::Schema::Loader::DBI
16 Oracle Implementation.
17  
18 =head1 DESCRIPTION
19  
20 See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
21  
22 =cut
23  
24 0 ▶sub _setup {
Subroutine _setup: not called CC=7 SCAR=40.3
25 0 my $self = shift;
26  
27 0 $self->next::method(@_);
28  
29 0 my ($current_schema) = $self->dbh->selectrow_array('SELECT USER FROM DUAL');
30  
31 0 ▶ $self->db_schema([ $current_schema ]) unless $self->db_schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->db_schema 0 0 0
32  
33 0 ▶ if (@{ $self->db_schema } == 1 && $self->db_schema->[0] ne '%'
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->db_schema;} == 1 and $self->db_schema->[0] ne "%" and lc $self->db_schema->[0] ne lc $current_schema) 0 0 0
Condition0%0/6
@{$self->db_schema;} == 1 and $self->db_schema->[0] ne "%" and lc $self->db_schema->[0] ne lc $current_schema
!ll&&!rl&&r
000
@{$self->db_schema;} == 1 and $self->db_schema->[0] ne "%"
!ll&&!rl&&r
000
MC/DC0%0/3
@{$self->db_schema;} == 1 and $self->db_schema->[0] ne "%" and lc $self->db_schema->[0] ne lc $current_schema
@{$self->db_schema;} == 1 $self->db_schema->[0] ne "%" lc $self->db_schema->[0] ne lc $current_schema
Truth table0%0/4
A and B and C
A= @{$self->db_schema;} == 1B= $self->db_schema->[0] ne "%"C= lc $self->db_schema->[0] ne lc $current_schema
ABCresult
0XX0
10X0
1100
1111
34 && lc($self->db_schema->[0]) ne lc($current_schema)) {
35 0 $self->dbh->do('ALTER SESSION SET current_schema=' . $self->db_schema->[0]);
36 }
37  
38 0 ▶ if (not defined $self->preserve_case) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->preserve_case) { } 0 0 0
elsif ($self->preserve_case) { } 0 0 0
39 0 $self->preserve_case(0);
40 }
41 elsif ($self->preserve_case) {
42 0 $self->schema->storage->sql_maker->quote_char('"');
43 0 $self->schema->storage->sql_maker->name_sep('.');
44 }
45 }
46  
47 0 ▶sub _build_name_sep { '.' }
Subroutine _build_name_sep: not called CC=1 SCAR=6.9
48  
49 0 ▶sub _system_schemas {
Subroutine _system_schemas: not called CC=1 SCAR=6.9
50 0 my $self = shift;
51  
52 # From http://www.adp-gmbh.ch/ora/misc/known_schemas.html
53  
54 0 return ($self->next::method(@_), qw/ANONYMOUS APEX_PUBLIC_USER APEX_030200 APPQOSSYS CTXSYS DBSNMP DIP DMSYS EXFSYS LBACSYS MDDATA MDSYS MGMT_VIEW OLAPSYS ORACLE_OCM ORDDATA ORDPLUGINS ORDSYS OUTLN SI_INFORMTN_SCHEMA SPATIAL_CSW_ADMIN_USR SPATIAL_WFS_ADMIN_USR SYS SYSMAN SYSTEM TRACESRV MTSSYS OASPUBLIC OWBSYS OWBSYS_AUDIT WEBSYS WK_PROXY WKSYS WK_TEST WMSYS XDB OSE$HTTP$ADMIN AURORA$JIS$UTILITY$ AURORA$ORB$UNAUTHENTICATED/, qr/^FLOWS_\d\d\d\d\d\d\z/);
55 }
56  
57 0 ▶sub _system_tables {
Subroutine _system_tables: not called CC=1 SCAR=6.9
58 0 my $self = shift;
59  
60 return (
61 0 $self->next::method(@_),
62 'PLAN_TABLE',
63 qr/\ABIN\$.*\$\d+\z/, # Tables in the recycle bin
64 );
65 }
66  
67 0 ▶sub _dbh_tables {
Subroutine _dbh_tables: not called CC=1 SCAR=6.9
68 0 my ($self, $schema) = @_;
69  
70 0 return $self->dbh->tables(undef, $schema, '%', 'TABLE,VIEW');
71 }
72  
73 0 ▶sub _filter_tables {
Subroutine _filter_tables: not called CC=1 SCAR=6.9
74 0 my $self = shift;
75  
76 # silence a warning from older DBD::Oracles in tests
77 0 local $SIG{__WARN__} = sigwarn_silencer(
78 qr/^Field \d+ has an Oracle type \(\d+\) which is not explicitly supported/
79 );
80  
81 0 return $self->next::method(@_);
82 }
83  
84 0 ▶sub _table_fk_info {
Subroutine _table_fk_info: not called CC=4 SCAR=30.0
85 0 my $self = shift;
86 0 my ($table) = @_;
87  
88 0 my $rels = $self->next::method(@_);
89  
90 0 my $deferrable_sth = $self->dbh->prepare_cached(<<'EOF');
91 select deferrable from all_constraints
92 where owner = ? and table_name = ? and constraint_name = ? and status = 'ENABLED'
93 EOF
94  
95 0 my @enabled_rels;
96 0 foreach my $rel (@$rels) {
97 # Oracle does not have update rules
98 0 $rel->{attrs}{on_update} = 'NO ACTION';;
99  
100 # DBD::Oracle's foreign_key_info does not return DEFERRABILITY, so we get it ourselves
101 # Also use this to filter out disabled foreign keys, which are returned by DBD::Oracle < 1.76
102 my $deferrable = $self->dbh->selectrow_array(
103 $deferrable_sth, undef, $table->schema, $table->name, $rel->{_constraint_name}
104 0 ▶ ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $deferrable = $self->dbh->selectrow_array($deferrable_sth, undef, $table->schema, $table->name, $rel->{"_constraint_name"}) or next 0 0 0
105  
106 0 ▶ $rel->{attrs}{is_deferrable} = $deferrable =~ /^DEFERRABLE/i ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$deferrable =~ /^DEFERRABLE/i ? : 0 0 0
107 0 push @enabled_rels, $rel;
108 }
109  
110 0 return \@enabled_rels;
111 }
112  
113 0 ▶sub _table_uniq_info {
Subroutine _table_uniq_info: not called CC=2 SCAR=17.9
114 0 my ($self, $table) = @_;
115  
116 0 my $sth = $self->dbh->prepare_cached(<<'EOF', {}, 1);
117 SELECT ac.constraint_name, acc.column_name
118 FROM all_constraints ac, all_cons_columns acc
119 WHERE acc.table_name=? AND acc.owner = ?
120 AND ac.table_name = acc.table_name AND ac.owner = acc.owner
121 AND acc.constraint_name = ac.constraint_name
122 AND ac.constraint_type = 'U'
123 AND ac.status = 'ENABLED'
124 ORDER BY acc.position
125 EOF
126  
127 0 $sth->execute($table->name, $table->schema);
128  
129 0 my %constr_names;
130  
131 0 ▶ while(my $constr = $sth->fetchrow_arrayref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $constr = $sth->fetchrow_arrayref) 0 0 0
132 0 my $constr_name = $self->_lc($constr->[0]);
133 0 my $constr_col = $self->_lc($constr->[1]);
134 0 push @{$constr_names{$constr_name}}, $constr_col;
135 }
136  
137 0 return [ map { [ $_ => $constr_names{$_} ] } sort keys %constr_names ];
138 }
139  
140 0 ▶sub _table_comment {
Subroutine _table_comment: not called CC=2 SCAR=17.9
141 0 my $self = shift;
142 0 my ($table) = @_;
143  
144 0 my $table_comment = $self->next::method(@_);
145  
146 0 ▶ return $table_comment if $table_comment;
Branch: 1 branch
BranchTrueFalseTotal
if $table_comment 0 0 0
147  
148 0 ($table_comment) = $self->dbh->selectrow_array(<<'EOF', {}, $table->schema, $table->name);
149 SELECT comments FROM all_tab_comments
150 WHERE owner = ?
151 AND table_name = ?
152 AND (table_type = 'TABLE' OR table_type = 'VIEW')
153 EOF
154  
155 0 return $table_comment
156 }
157  
158 0 ▶sub _column_comment {
Subroutine _column_comment: not called CC=2 SCAR=17.9
159 0 my $self = shift;
160 0 my ($table, $column_number, $column_name) = @_;
161  
162 0 my $column_comment = $self->next::method(@_);
163  
164 0 ▶ return $column_comment if $column_comment;
Branch: 1 branch
BranchTrueFalseTotal
if $column_comment 0 0 0
165  
166 0 ($column_comment) = $self->dbh->selectrow_array(<<'EOF', {}, $table->schema, $table->name, $self->_uc($column_name));
167 SELECT comments FROM all_col_comments
168 WHERE owner = ?
169 AND table_name = ?
170 AND column_name = ?
171 EOF
172  
173 0 return $column_comment
174 }
175  
176 0 ▶sub _columns_info_for {
Subroutine _columns_info_for: not called CC=55 SCAR=79.9
177 0 my $self = shift;
178 0 my ($table) = @_;
179  
180 0 my $result = $self->next::method(@_);
181  
182 0 local $self->dbh->{LongReadLen} = 1_000_000;
183 0 local $self->dbh->{LongTruncOk} = 1;
184  
185 0 my $sth = $self->dbh->prepare_cached(<<'EOF', {}, 1);
186 SELECT trigger_body
187 FROM all_triggers
188 WHERE table_name = ? AND table_owner = ? AND status = 'ENABLED'
189 AND upper(trigger_type) LIKE '%BEFORE EACH ROW%' AND lower(triggering_event) LIKE '%insert%'
190 EOF
191  
192 0 $sth->execute($table->name, $table->schema);
193  
194 0 ▶ while (my ($trigger_body) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($trigger_body) = $sth->fetchrow_array) 0 0 0
195 0 ▶ if (my ($seq_schema, $seq_name) = $trigger_body =~ /(?:"?(\w+)"?\.)?"?(\w+)"?\.nextval/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $trigger_body =~ /(?:"?(\w+)"?\.)?"?(\w+)"?\.nextval/i) 0 0 0
196 0 ▶ if (my ($col_name) = $trigger_body =~ /:new\.(\w+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($col_name) = $trigger_body =~ /:new\.(\w+)/i) 0 0 0
197 0 $col_name = $self->_lc($col_name);
198  
199 0 $result->{$col_name}{is_auto_increment} = 1;
200  
201 0 ▶ $seq_schema = $self->_lc($seq_schema || $table->schema);
Condition0%0/3
$seq_schema || $table->schema
l!l&&r!l&&!r
000
MC/DC0%0/2
$seq_schema || $table->schema
$seq_schema $table->schema
Truth table0%0/3
A || B
A= $seq_schemaB= $table->schema
ABresult
1X1
011
000
202 0 $seq_name = $self->_lc($seq_name);
203  
204 0 ▶ $result->{$col_name}{sequence} = ($self->qualify_objects ? ($seq_schema . '.') : '') . $seq_name;
Branch: 1 branch
BranchTrueFalseTotal
$self->qualify_objects ? : 0 0 0
205 }
206 }
207 }
208  
209 # Old DBD::Oracle report the size in (UTF-16) bytes, not characters
210 0 ▶ my $nchar_size_factor = $DBD::Oracle::VERSION >= 1.52 ? 1 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$DBD::Oracle::VERSION >= 1.52 ? : 0 0 0
211  
212 0 ▶ while (my ($col, $info) = each %$result) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$result) 0 0 0
213 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
214  
215 0 my $sth = $self->dbh->prepare_cached(<<'EOF', {}, 1);
216 SELECT data_type, data_length
217 FROM all_tab_columns
218 WHERE column_name = ? AND table_name = ? AND owner = ?
219 EOF
220 0 $sth->execute($self->_uc($col), $table->name, $table->schema);
221 0 my ($data_type, $data_length) = $sth->fetchrow_array;
222 0 $sth->finish;
223 0 $data_type = lc $data_type;
224  
225 0 ▶ if ($data_type =~ /^(?:n(?:var)?char2?|u?rowid|nclob|timestamp\(\d+\)(?: with(?: local)? time zone)?|binary_(?:float|double))\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type =~ /^(?:n(?:var)?char2?|u?rowid|nclob|timestamp\(\d+\)(?: with(?: local)? time zone)?|binary_(?:float|double))\z/i) 0 0 0
226 0 $info->{data_type} = $data_type;
227  
228 0 ▶ if ($data_type =~ /^u?rowid\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type =~ /^u?rowid\z/i) 0 0 0
229 0 $info->{size} = $data_length;
230 }
231 }
232  
233 0 ▶ if ($info->{data_type} =~ /^(?:n?[cb]lob|long(?: raw)?|bfile|date|binary_(?:float|double)|rowid)\z/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"data_type"} =~ /^(?:n?[cb]lob|long(?: raw)?|bfile|date|binary_(?:float|double)|rowid)\z/i) 0 0 0
234 0 delete $info->{size};
235 }
236  
237 0 ▶ if ($info->{data_type} =~ /^n(?:var)?char2?\z/i) {
Branch: 17 branches
BranchTrueFalseTotal
if ($info->{'data_type'} =~ /^n(?:var)?char2?\z/i) { } 0 0 0
elsif ($info->{'data_type'} =~ /^(?:var)?char2?\z/i) { } 0 0 0
elsif (lc($info->{'data_type'}) =~ /^(?:number|decimal)\z/i) { } 0 0 0
elsif (my($precision) = $info->{'data_type'} =~ /^timestamp\((\d+)\)(?: with (?:local )?time zone)?\z/i) { } 0 0 0
elsif ($info->{'data_type'} =~ /timestamp/i and ref $info->{'size'} and $info->{'size'}[0] == 0) { } 0 0 0
elsif (($precision) = $info->{'data_type'} =~ /^interval year\((\d+)\) to month\z/i) { } 0 0 0
elsif (() = $info->{'data_type'} =~ /^interval day\((\d+)\) to second\((\d+)\)\z/i) { } 0 0 0
elsif ($info->{'data_type'} =~ /^interval year to month\z/i and ref $info->{'size'}) { } 0 0 0
elsif ($info->{'data_type'} =~ /^interval day to second\z/i and ref $info->{'size'}) { } 0 0 0
elsif (lc $info->{'data_type'} eq 'float') { } 0 0 0
elsif (lc $info->{'data_type'} eq 'double precision') { } 0 0 0
elsif (lc $info->{'data_type'} eq 'urowid' and $info->{'size'} == 4000) { } 0 0 0
elsif ($info->{'data_type'} eq '-9104') { } 0 0 0
elsif ($info->{'data_type'} eq '-2') { } 0 0 0
elsif (lc $info->{'data_type'} eq 'date') { } 0 0 0
elsif (lc $info->{'data_type'} eq 'binary_float') { } 0 0 0
elsif (lc $info->{'data_type'} eq 'binary_double') { } 0 0 0
238 0 ▶ if (ref $info->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info->{'size'}) { } 0 0 0
239 0 $info->{size} = $info->{size}[0] / 8;
240 }
241 else {
242 0 $info->{size} = $info->{size} / $nchar_size_factor;
243 }
244 }
245 elsif ($info->{data_type} =~ /^(?:var)?char2?\z/i) {
246 0 ▶ if (ref $info->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info->{"size"}) 0 0 0
247 0 $info->{size} = $info->{size}[0];
248 }
249 }
250 elsif (lc($info->{data_type}) =~ /^(?:number|decimal)\z/i) {
251 0 $info->{original}{data_type} = 'number';
252 0 $info->{data_type} = 'numeric';
253  
254 0 ▶ if (try { $info->{size}[0] == 38 && $info->{size}[1] == 0 }) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
if (&try(sub { $info->{"size"}[0] == 38 and $info->{"size"}[1] == 0; } )) 0 0 0
$info->{"size"}[0] == 38 and $info->{"size"}[1] == 0 0 0 0
255 0 $info->{original}{size} = $info->{size};
256  
257 0 $info->{data_type} = 'integer';
258 0 delete $info->{size};
259 }
260 }
261 elsif (my ($precision) = $info->{data_type} =~ /^timestamp\((\d+)\)(?: with (?:local )?time zone)?\z/i) {
262 0 $info->{data_type} = join ' ', $info->{data_type} =~ /[a-z]+/ig;
263  
264 0 ▶ if ($precision == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precision == 6) { } 0 0 0
265 0 delete $info->{size};
266 }
267 else {
268 0 $info->{size} = $precision;
269 }
270 }
271 ▶ elsif ($info->{data_type} =~ /timestamp/i && ref $info->{size} && $info->{size}[0] == 0) {
Condition0%0/6
$info->{"data_type"} =~ /timestamp/i and ref $info->{"size"} and $info->{"size"}[0] == 0
!ll&&!rl&&r
000
$info->{"data_type"} =~ /timestamp/i and ref $info->{"size"}
!ll&&!rl&&r
000
MC/DC0%0/3
$info->{"data_type"} =~ /timestamp/i and ref $info->{"size"} and $info->{"size"}[0] == 0
$info->{"data_type"} =~ /timestamp/i ref $info->{"size"} $info->{"size"}[0] == 0
Truth table0%0/4
A and B and C
A= $info->{"data_type"} =~ /timestamp/iB= ref $info->{"size"}C= $info->{"size"}[0] == 0
ABCresult
0XX0
10X0
1100
1111
272 0 my $size = $info->{size}[1];
273 0 delete $info->{size};
274 0 ▶ $info->{size} = $size unless $size == 6;
Branch: 1 branch
BranchTrueFalseTotal
unless $size == 6 0 0 0
275 }
276 elsif (($precision) = $info->{data_type} =~ /^interval year\((\d+)\) to month\z/i) {
277 0 $info->{data_type} = join ' ', $info->{data_type} =~ /[a-z]+/ig;
278  
279 0 ▶ if ($precision == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precision == 2) { } 0 0 0
280 0 delete $info->{size};
281 }
282 else {
283 0 $info->{size} = $precision;
284 }
285 }
286 elsif (my ($day_precision, $second_precision) = $info->{data_type} =~ /^interval day\((\d+)\) to second\((\d+)\)\z/i) {
287 0 $info->{data_type} = join ' ', $info->{data_type} =~ /[a-z]+/ig;
288  
289 0 ▶ if ($day_precision == 2 && $second_precision == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($day_precision == 2 and $second_precision == 6) { } 0 0 0
Condition0%0/3
$day_precision == 2 and $second_precision == 6
!ll&&!rl&&r
000
MC/DC0%0/2
$day_precision == 2 and $second_precision == 6
$day_precision == 2 $second_precision == 6
Truth table0%0/3
A and B
A= $day_precision == 2B= $second_precision == 6
ABresult
0X0
100
111
290 0 delete $info->{size};
291 }
292 else {
293 0 $info->{size} = [ $day_precision, $second_precision ];
294 }
295 }
296 ▶ elsif ($info->{data_type} =~ /^interval year to month\z/i && ref $info->{size}) {
Condition0%0/3
$info->{"data_type"} =~ /^interval year to month\z/i and ref $info->{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"data_type"} =~ /^interval year to month\z/i and ref $info->{"size"}
$info->{"data_type"} =~ /^interval year to month\z/i ref $info->{"size"}
Truth table0%0/3
A and B
A= $info->{"data_type"} =~ /^interval year to month\z/iB= ref $info->{"size"}
ABresult
0X0
100
111
297 0 my $precision = $info->{size}[0];
298  
299 0 ▶ if ($precision == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precision == 2) { } 0 0 0
300 0 delete $info->{size};
301 }
302 else {
303 0 $info->{size} = $precision;
304 }
305 }
306 ▶ elsif ($info->{data_type} =~ /^interval day to second\z/i && ref $info->{size}) {
Condition0%0/3
$info->{"data_type"} =~ /^interval day to second\z/i and ref $info->{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"data_type"} =~ /^interval day to second\z/i and ref $info->{"size"}
$info->{"data_type"} =~ /^interval day to second\z/i ref $info->{"size"}
Truth table0%0/3
A and B
A= $info->{"data_type"} =~ /^interval day to second\z/iB= ref $info->{"size"}
ABresult
0X0
100
111
307 0 ▶ if ($info->{size}[0] == 2 && $info->{size}[1] == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"size"}[0] == 2 and $info->{"size"}[1] == 6) 0 0 0
Condition0%0/3
$info->{"size"}[0] == 2 and $info->{"size"}[1] == 6
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"size"}[0] == 2 and $info->{"size"}[1] == 6
$info->{"size"}[0] == 2 $info->{"size"}[1] == 6
Truth table0%0/3
A and B
A= $info->{"size"}[0] == 2B= $info->{"size"}[1] == 6
ABresult
0X0
100
111
308 0 delete $info->{size};
309 }
310 }
311 elsif (lc($info->{data_type}) eq 'float') {
312 0 $info->{original}{data_type} = 'float';
313 0 $info->{original}{size} = $info->{size};
314  
315 0 ▶ if ($info->{size} <= 63) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{'size'} <= 63) { } 0 0 0
316 0 $info->{data_type} = 'real';
317 }
318 else {
319 0 $info->{data_type} = 'double precision';
320 }
321 0 delete $info->{size};
322 }
323 elsif (lc($info->{data_type}) eq 'double precision') {
324 0 $info->{original}{data_type} = 'float';
325  
326 0 ▶ my $size = try { $info->{size}[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
327  
328 0 $info->{original}{size} = $size;
329  
330 0 ▶ if ($size <= 63) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size <= 63) 0 0 0
331 0 $info->{data_type} = 'real';
332 }
333 0 delete $info->{size};
334 }
335 ▶ elsif (lc($info->{data_type}) eq 'urowid' && $info->{size} == 4000) {
Condition0%0/3
lc $info->{"data_type"} eq "urowid" and $info->{"size"} == 4000
!ll&&!rl&&r
000
MC/DC0%0/2
lc $info->{"data_type"} eq "urowid" and $info->{"size"} == 4000
lc $info->{"data_type"} eq "urowid" $info->{"size"} == 4000
Truth table0%0/3
A and B
A= lc $info->{"data_type"} eq "urowid"B= $info->{"size"} == 4000
ABresult
0X0
100
111
336 0 delete $info->{size};
337 }
338 elsif ($info->{data_type} eq '-9104') {
339 0 $info->{data_type} = 'rowid';
340 0 delete $info->{size};
341 }
342 elsif ($info->{data_type} eq '-2') {
343 0 $info->{data_type} = 'raw';
344 0 ▶ $info->{size} = try { $info->{size}[0] / 2 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
345 }
346 elsif (lc($info->{data_type}) eq 'date') {
347 0 $info->{data_type} = 'datetime';
348 0 $info->{original}{data_type} = 'date';
349 }
350 elsif (lc($info->{data_type}) eq 'binary_float') {
351 0 $info->{data_type} = 'real';
352 0 $info->{original}{data_type} = 'binary_float';
353 }
354 elsif (lc($info->{data_type}) eq 'binary_double') {
355 0 $info->{data_type} = 'double precision';
356 0 $info->{original}{data_type} = 'binary_double';
357 }
358  
359 # DEFAULT could be missed by ::DBI because of ORA-24345
360 0 ▶ if (not defined $info->{default_value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info->{"default_value"}) 0 0 0
361 0 local $self->dbh->{LongReadLen} = 1_000_000;
362 0 local $self->dbh->{LongTruncOk} = 1;
363 0 my $sth = $self->dbh->prepare_cached(<<'EOF', {}, 1);
364 SELECT data_default
365 FROM all_tab_columns
366 WHERE column_name = ? AND table_name = ? AND owner = ?
367 EOF
368 0 $sth->execute($self->_uc($col), $table->name, $table->schema);
369 0 my ($default) = $sth->fetchrow_array;
370 0 $sth->finish;
371  
372 # this is mostly copied from ::DBI::QuotedDefault
373 0 ▶ if (defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 0 0 0
374 0 s/^\s+//, s/\s+\z// for $default;
375  
376 0 ▶ if ($default =~ /^'(.*?)'\z/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($default =~ /^'(.*?)'\z/) { } 0 0 0
elsif ($default =~ /^(-?\d.*?)\z/) { } 0 0 0
elsif ($default =~ /^NULL\z/i) { } 0 0 0
elsif ($default ne '') { } 0 0 0
377 0 $info->{default_value} = $1;
378 }
379 elsif ($default =~ /^(-?\d.*?)\z/) {
380 0 $info->{default_value} = $1;
381 }
382 elsif ($default =~ /^NULL\z/i) {
383 0 my $null = 'null';
384 0 $info->{default_value} = \$null;
385 }
386 elsif ($default ne '') {
387 0 my $val = $default;
388 0 $info->{default_value} = \$val;
389 }
390 }
391 }
392  
393 0 ▶ if ((try { lc(${ $info->{default_value} }) }||'') eq 'sysdate') {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ((&try(sub { lc ${$info->{"default_value"};}; } ) || "") eq "sysdate") 0 0 0
Condition0%0/2
&try(sub { lc ${$info->{'default_value'};}; } ) || ''
l!l
00
MC/DC0%0/1
&try(sub { lc ${$info->{'default_value'};}; } ) || ''
&try(sub { lc ${$info->{'default_value'};}; } )
Truth table0%0/2
A
A= &try(sub { lc ${$info->{'default_value'};}; } )
Aresult
11
00
394 0 my $current_timestamp = 'current_timestamp';
395 0 $info->{default_value} = \$current_timestamp;
396  
397 0 my $sysdate = 'sysdate';
398 0 $info->{original}{default_value} = \$sysdate;
399 }
400 }
401  
402 0 return $result;
403 }
404  
405 0 ▶sub _dbh_column_info {
Subroutine _dbh_column_info: not called CC=1 SCAR=6.9
406 0 my $self = shift;
407 0 my ($dbh) = @_;
408  
409 # try to avoid ORA-24345
410 0 local $dbh->{LongReadLen} = 1_000_000;
411 0 local $dbh->{LongTruncOk} = 1;
412  
413 0 return $self->next::method(@_);
414 }
415  
416 0 ▶sub _view_definition {
Subroutine _view_definition: not called CC=1 SCAR=6.9
417 0 my ($self, $view) = @_;
418  
419 0 return scalar $self->schema->storage->dbh->selectrow_array(<<'EOF', {}, $view->schema, $view->name);
420 SELECT text
421 FROM all_views
422 WHERE owner = ? AND view_name = ?
423 EOF
424 }
425  
426 =head1 SEE ALSO
427  
428 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
429 L<DBIx::Class::Schema::Loader::DBI>
430  
431 =head1 AUTHORS
432  
433 See L<DBIx::Class::Schema::Loader/AUTHORS>.
434  
435 =head1 LICENSE
436  
437 This library is free software; you can redistribute it and/or modify it under
438 the same terms as Perl itself.
439  
440 =cut
441  
442 1 1;
443 # vim:et sts=4 sw=4 tw=0:
↑ Summary blib/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm »