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

filter: Statementstmt 11.0% 15 / 136 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 37 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 33.3% 4 / 12 Podpod n/a totaltotal 6.7% 19 / 283 SCAR 77.8
CC
53
Cov
6%
_columns_info_for
1482.0
_table_uniq_info
72.0
_setup
20.0
CRAP 2384.3
« blib/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm ↑ Summary blib/lib/DBIx/Class/Schema/Loader/DBI/ODBC/ACCESS.pm »
1 package DBIx::Class::Schema::Loader::DBI::Pg;
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  
8 1 our $VERSION = '0.07050';
9  
10 =head1 NAME
11  
12 DBIx::Class::Schema::Loader::DBI::Pg - DBIx::Class::Schema::Loader::DBI
13 PostgreSQL Implementation.
14  
15 =head1 DESCRIPTION
16  
17 See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
18  
19 =cut
20  
21 sub _setup {
22 0 ▶ my $self = shift;
Subroutine _setup: not called CC=4 SCAR=30.0
23  
24 0 $self->next::method(@_);
25  
26 0 ▶ $self->{db_schema} ||= ['public'];
Condition0%0/2
$self->{"db_schema"} ||= ["public"]
l!l
00
MC/DC0%0/1
$self->{"db_schema"} ||= ["public"]
$self->{"db_schema"}
Truth table0%0/2
A
A= $self->{"db_schema"}
Aresult
11
00
27  
28 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
29 0 $self->preserve_case(0);
30 }
31 elsif ($self->preserve_case) {
32 0 $self->schema->storage->sql_maker->quote_char('"');
33 0 $self->schema->storage->sql_maker->name_sep('.');
34 }
35 }
36  
37 sub _system_schemas {
38 0 ▶ my $self = shift;
Subroutine _system_schemas: not called CC=1 SCAR=6.9
39  
40 0 return ($self->next::method(@_), 'pg_catalog');
41 }
42  
43 1 my %pg_rules = (
44 a => 'NO ACTION',
45 r => 'RESTRICT',
46 c => 'CASCADE',
47 n => 'SET NULL',
48 d => 'SET DEFAULT',
49 );
50  
51 sub _table_fk_info {
52 0 ▶ my ($self, $table) = @_;
Subroutine _table_fk_info: not called CC=4 SCAR=30.0
53  
54 0 my $sth = $self->dbh->prepare_cached(<<"EOF");
55 select constr.conname, to_ns.nspname, to_class.relname, from_col.attname, to_col.attname,
56 constr.confdeltype, constr.confupdtype, constr.condeferrable
57 from pg_catalog.pg_constraint constr
58 join pg_catalog.pg_namespace from_ns on constr.connamespace = from_ns.oid
59 join pg_catalog.pg_class from_class on constr.conrelid = from_class.oid and from_class.relnamespace = from_ns.oid
60 join pg_catalog.pg_class to_class on constr.confrelid = to_class.oid
61 join pg_catalog.pg_namespace to_ns on to_class.relnamespace = to_ns.oid
62 -- can't do unnest() until 8.4, so join against a series table instead
63 join pg_catalog.generate_series(1, pg_catalog.current_setting('max_index_keys')::integer) colnum(i)
64 on colnum.i <= pg_catalog.array_upper(constr.conkey,1)
65 join pg_catalog.pg_attribute to_col
66 on to_col.attrelid = constr.confrelid
67 and to_col.attnum = constr.confkey[colnum.i]
68 join pg_catalog.pg_attribute from_col
69 on from_col.attrelid = constr.conrelid
70 and from_col.attnum = constr.conkey[colnum.i]
71 where from_ns.nspname = ?
72 and from_class.relname = ?
73 and from_class.relkind = 'r'
74 and constr.contype = 'f'
75 order by constr.conname, colnum.i
76 EOF
77  
78 0 $sth->execute($table->schema, $table->name);
79  
80 0 my %rels;
81  
82 0 ▶ while (my ($fk, $remote_schema, $remote_table, $col, $remote_col,
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
83 $delete_rule, $update_rule, $is_deferrable) = $sth->fetchrow_array) {
84 0 push @{ $rels{$fk}{local_columns} }, $self->_lc($col);
85 0 push @{ $rels{$fk}{remote_columns} }, $self->_lc($remote_col);
86  
87 $rels{$fk}{remote_table} = DBIx::Class::Schema::Loader::Table->new(
88 loader => $self,
89 name => $remote_table,
90 schema => $remote_schema,
91 0 ▶ ) unless exists $rels{$fk}{remote_table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rels{$fk}{"remote_table"} 0 0 0
92  
93 $rels{$fk}{attrs} ||= {
94 on_delete => $pg_rules{$delete_rule},
95 0 ▶ on_update => $pg_rules{$update_rule},
Condition0%0/2
$rels{$fk}{"attrs"} ||= {"on_delete", $pg_rules{$delete_rule}, "on_update", $pg_rules{$update_rule}, "is_deferrable", $is_deferrable}
l!l
00
MC/DC0%0/1
$rels{$fk}{"attrs"} ||= {"on_delete", $pg_rules{$delete_rule}, "on_update", $pg_rules{$update_rule}, "is_deferrable", $is_deferrable}
$rels{$fk}{"attrs"}
Truth table0%0/2
A
A= $rels{$fk}{"attrs"}
Aresult
11
00
96 is_deferrable => $is_deferrable,
97 };
98 }
99  
100 0 return [ map { $rels{$_} } sort keys %rels ];
101 }
102  
103  
104 sub _table_uniq_info {
105 0 ▶ my ($self, $table) = @_;
Subroutine _table_uniq_info: not called CC=8 SCAR=42.8
106  
107 # Use the default support if available
108 0 ▶ return $self->next::method($table)
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::Pg::VERSION >= "1.5" 0 0 0
109 if $DBD::Pg::VERSION >= 1.50;
110  
111 0 my @uniqs;
112  
113 # Most of the SQL here is mostly based on
114 # Rose::DB::Object::Metadata::Auto::Pg, after some prodding from
115 # John Siracusa to use his superior SQL code :)
116  
117 0 ▶ my $attr_sth = $self->{_cache}->{pg_attr_sth} ||= $self->dbh->prepare(
Condition0%0/3
$self->{"_cache"}{"pg_attr_sth"} ||= $self->dbh->prepare("SELECT attname FROM pg_catalog.pg_attribute\n WHERE attrelid = ? AND attnum = ?")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_cache"}{"pg_attr_sth"} ||= $self->dbh->prepare("SELECT attname FROM pg_catalog.pg_attribute\n WHERE attrelid = ? AND attnum = ?")
$self->{"_cache"}{"pg_attr_sth"} $self->dbh->prepare("SELECT attname FROM pg_catalog.pg_attribute\n WHERE attrelid = ? AND attnum = ?")
Truth table0%0/3
A ||= B
A= $self->{"_cache"}{"pg_attr_sth"}B= $self->dbh->prepare("SELECT attname FROM pg_catalog.pg_attribute\n WHERE attrelid = ? AND attnum = ?")
ABresult
1X1
011
000
118 q{SELECT attname FROM pg_catalog.pg_attribute
119 WHERE attrelid = ? AND attnum = ?}
120 );
121  
122 0 ▶ my $uniq_sth = $self->{_cache}->{pg_uniq_sth} ||= $self->dbh->prepare(
Condition0%0/3
$self->{"_cache"}{"pg_uniq_sth"} ||= $self->dbh->prepare("SELECT x.indrelid, i.relname, x.indkey\n FROM\n pg_catalog.pg_index x\n JOIN pg_catalog.pg_class c ON c.oid = x.indrelid\n JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n WHERE\n x.indisunique = 't' AND\n x.indpred IS NULL AND\n c.relkind = 'r' AND\n i.relkind = 'i' AND\n n.nspname = ? AND\n c.relname = ?\n ORDER BY i.relname")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_cache"}{"pg_uniq_sth"} ||= $self->dbh->prepare("SELECT x.indrelid, i.relname, x.indkey\n FROM\n pg_catalog.pg_index x\n JOIN pg_catalog.pg_class c ON c.oid = x.indrelid\n JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n WHERE\n x.indisunique = 't' AND\n x.indpred IS NULL AND\n c.relkind = 'r' AND\n i.relkind = 'i' AND\n n.nspname = ? AND\n c.relname = ?\n ORDER BY i.relname")
$self->{"_cache"}{"pg_uniq_sth"} $self->dbh->prepare("SELECT x.indrelid, i.relname, x.indkey\n FROM\n pg_catalog.pg_index x\n JOIN pg_catalog.pg_class c ON c.oid = x.indrelid\n JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n WHERE\n x.indisunique = 't' AND\n x.indpred IS NULL AND\n c.relkind = 'r' AND\n i.relkind = 'i' AND\n n.nspname = ? AND\n c.relname = ?\n ORDER BY i.relname")
Truth table0%0/3
A ||= B
A= $self->{"_cache"}{"pg_uniq_sth"}B= $self->dbh->prepare("SELECT x.indrelid, i.relname, x.indkey\n FROM\n pg_catalog.pg_index x\n JOIN pg_catalog.pg_class c ON c.oid = x.indrelid\n JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n WHERE\n x.indisunique = 't' AND\n x.indpred IS NULL AND\n c.relkind = 'r' AND\n i.relkind = 'i' AND\n n.nspname = ? AND\n c.relname = ?\n ORDER BY i.relname")
ABresult
1X1
011
000
123 q{SELECT x.indrelid, i.relname, x.indkey
124 FROM
125 pg_catalog.pg_index x
126 JOIN pg_catalog.pg_class c ON c.oid = x.indrelid
127 JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid
128 JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
129 WHERE
130 x.indisunique = 't' AND
131 x.indpred IS NULL AND
132 c.relkind = 'r' AND
133 i.relkind = 'i' AND
134 n.nspname = ? AND
135 c.relname = ?
136 ORDER BY i.relname}
137 );
138  
139 0 $uniq_sth->execute($table->schema, $table->name);
140 0 ▶ while(my $row = $uniq_sth->fetchrow_arrayref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $uniq_sth->fetchrow_arrayref) 0 0 0
141 0 my ($tableid, $indexname, $col_nums) = @$row;
142 0 $col_nums =~ s/^\s+//;
143 0 my @col_nums = split(/\s+/, $col_nums);
144 0 my @col_names;
145  
146 0 foreach (@col_nums) {
147 0 $attr_sth->execute($tableid, $_);
148 0 my $name_aref = $attr_sth->fetchrow_arrayref;
149 0 ▶ push(@col_names, $self->_lc($name_aref->[0])) if $name_aref;
Branch: 1 branch
BranchTrueFalseTotal
if $name_aref 0 0 0
150 }
151  
152 # skip indexes with missing column names (e.g. expression indexes)
153 0 ▶ if(@col_names == @col_nums) {
Branch: 1 branch
BranchTrueFalseTotal
if (@col_names == @col_nums) 0 0 0
154 0 push(@uniqs, [ $indexname => \@col_names ]);
155 }
156 }
157  
158 0 return \@uniqs;
159 }
160  
161 sub _table_comment {
162 0 ▶ my $self = shift;
Subroutine _table_comment: not called CC=2 SCAR=17.9
163 0 my ($table) = @_;
164  
165 0 my $table_comment = $self->next::method(@_);
166  
167 0 ▶ return $table_comment if $table_comment;
Branch: 1 branch
BranchTrueFalseTotal
if $table_comment 0 0 0
168  
169 0 ($table_comment) = $self->dbh->selectrow_array(<<'EOF', {}, $table->name, $table->schema);
170 SELECT pg_catalog.obj_description(oid)
171 FROM pg_catalog.pg_class
172 WHERE relname=? AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=?)
173 EOF
174  
175 0 return $table_comment
176 }
177  
178  
179 sub _column_comment {
180 0 ▶ my $self = shift;
Subroutine _column_comment: not called CC=2 SCAR=17.9
181 0 my ($table, $column_number, $column_name) = @_;
182  
183 0 my $column_comment = $self->next::method(@_);
184  
185 0 ▶ return $column_comment if $column_comment;
Branch: 1 branch
BranchTrueFalseTotal
if $column_comment 0 0 0
186  
187 0 return $self->dbh->selectrow_array(<<'EOF', {}, $column_number, $table->name, $table->schema);
188 SELECT pg_catalog.col_description(oid, ?)
189 FROM pg_catalog.pg_class
190 WHERE relname=? AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=?)
191 EOF
192 }
193  
194 # Make sure data_type's that don't need it don't have a 'size' column_info, and
195 # set the correct precision for datetime and varbit types.
196 sub _columns_info_for {
197 0 ▶ my $self = shift;
Subroutine _columns_info_for: not called CC=38 SCAR=73.0
198 0 my ($table) = @_;
199  
200 0 my ($result, $raw) = $self->next::method(@_);
201  
202 0 ▶ while (my ($col, $info) = each %$result) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$result) 0 0 0
203 0 my $data_type = $info->{data_type};
204  
205 # these types are fixed size
206 # XXX should this be a negative match?
207 0 ▶ if ($data_type =~
Branch: 7 branches
BranchTrueFalseTotal
if ($data_type =~ /^(?:bigint|int8|bigserial|serial8|bool(?:ean)?|box|bytea|cidr|circle|date|double precision|float8|inet|integer|int|int4|line|lseg|macaddr|money|path|point|polygon|real|float4|smallint|int2|serial|serial4|text)\z/i) { } 0 0 0
elsif ($data_type =~ /^(?:interval|time|timestamp)\b/i) { } 0 0 0
elsif ($data_type =~ /^(?:bit(?: varying)?|varbit)\z/i) { } 0 0 0
elsif ($data_type =~ /^(?:numeric|decimal)\z/i and my $size = $info->{'size'}) { } 0 0 0
elsif (lc $data_type eq 'character varying') { } 0 0 0
elsif (lc $data_type eq 'character') { } 0 0 0
elsif ($DBD::Pg::VERSION >= 3.005002 || $self->dbh->{'pg_server_version'} < 90100 and my $values = $raw->{$col}{'pg_enum_values'}) { } 0 0 0
208 /^(?:bigint|int8|bigserial|serial8|bool(?:ean)?|box|bytea|cidr|circle|date|double precision|float8|inet|integer|int|int4|line|lseg|macaddr|money|path|point|polygon|real|float4|smallint|int2|serial|serial4|text)\z/i) {
209 0 delete $info->{size};
210 }
211 # for datetime types, check if it has a precision or not
212 elsif ($data_type =~ /^(?:interval|time|timestamp)\b/i) {
213 0 ▶ if (lc($data_type) eq 'timestamp without time zone') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $data_type eq 'timestamp without time zone') { } 0 0 0
elsif (lc $data_type eq 'time without time zone') { } 0 0 0
214 0 $info->{data_type} = 'timestamp';
215 }
216 elsif (lc($data_type) eq 'time without time zone') {
217 0 $info->{data_type} = 'time';
218 }
219  
220 0 my ($precision) = $self->schema->storage->dbh
221 ->selectrow_array(<<EOF, {}, $table->name, $col);
222 SELECT datetime_precision
223 FROM information_schema.columns
224 WHERE table_name = ? and column_name = ?
225 EOF
226  
227 0 ▶ if ($data_type =~ /^time\b/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data_type =~ /^time\b/i) { } 0 0 0
elsif (not defined $precision && $precision =~ /^\d/ or $precision == 6) { } 0 0 0
228 0 ▶ if ((not defined $precision) || $precision !~ /^\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $precision && $precision =~ /^\d/) { } 0 0 0
Condition0%0/3
defined $precision && $precision =~ /^\d/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $precision && $precision =~ /^\d/
defined $precision $precision =~ /^\d/
Truth table0%0/3
A && B
A= defined $precisionB= $precision =~ /^\d/
ABresult
0X0
100
111
229 0 delete $info->{size};
230 }
231 else {
232 0 my ($integer_datetimes) = $self->dbh
233 ->selectrow_array('show integer_datetimes');
234  
235 0 ▶ my $max_precision =
Branch: 1 branch
BranchTrueFalseTotal
$integer_datetimes =~ /^on\z/i ? : 0 0 0
236 $integer_datetimes =~ /^on\z/i ? 6 : 10;
237  
238 0 ▶ if ($precision == $max_precision) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precision == $max_precision) { } 0 0 0
239 0 delete $info->{size};
240 }
241 else {
242 0 $info->{size} = $precision;
243 }
244 }
245 }
246 ▶ elsif ((not defined $precision) || $precision !~ /^\d/ || $precision == 6) {
Condition0%0/6
not defined $precision && $precision =~ /^\d/ or $precision == 6
l!l&&r!l&&!r
000
defined $precision && $precision =~ /^\d/
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $precision && $precision =~ /^\d/ or $precision == 6
defined $precision $precision =~ /^\d/ $precision == 6
Truth table0%0/4
not(A && B) or C
A= defined $precisionB= $precision =~ /^\d/C= $precision == 6
ABCresult
0XX1
10X1
1111
1100
247 0 delete $info->{size};
248 }
249 else {
250 0 $info->{size} = $precision;
251 }
252 }
253 elsif ($data_type =~ /^(?:bit(?: varying)?|varbit)\z/i) {
254 0 ▶ $info->{data_type} = 'varbit' if $data_type =~ /var/i;
Branch: 1 branch
BranchTrueFalseTotal
if $data_type =~ /var/i 0 0 0
255  
256 0 my ($precision) = $self->dbh->selectrow_array(<<EOF, {}, $table->name, $col);
257 SELECT character_maximum_length
258 FROM information_schema.columns
259 WHERE table_name = ? and column_name = ?
260 EOF
261  
262 0 ▶ $info->{size} = $precision if $precision;
Branch: 1 branch
BranchTrueFalseTotal
if $precision 0 0 0
263  
264 0 ▶ $info->{size} = 1 if (not $precision) && lc($data_type) eq 'bit';
Branch: 1 branch
BranchTrueFalseTotal
if not $precision and lc $data_type eq "bit" 0 0 0
Condition0%0/3
not $precision and lc $data_type eq "bit"
!ll&&!rl&&r
000
MC/DC0%0/2
not $precision and lc $data_type eq "bit"
not $precision lc $data_type eq "bit"
Truth table0%0/3
not(A) and B
A= not $precisionB= lc $data_type eq "bit"
ABresult
0X0
100
111
265 }
266 ▶ elsif ($data_type =~ /^(?:numeric|decimal)\z/i && (my $size = $info->{size})) {
Condition0%0/3
$data_type =~ /^(?:numeric|decimal)\z/i and my $size = $info->{"size"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data_type =~ /^(?:numeric|decimal)\z/i and my $size = $info->{"size"}
$data_type =~ /^(?:numeric|decimal)\z/i my $size = $info->{"size"}
Truth table0%0/3
A and B
A= $data_type =~ /^(?:numeric|decimal)\z/iB= my $size = $info->{"size"}
ABresult
0X0
100
111
267 0 $size =~ s/\s*//g;
268  
269 0 my ($scale, $precision) = split /,/, $size;
270  
271 0 $info->{size} = [ $precision, $scale ];
272 }
273 elsif (lc($data_type) eq 'character varying') {
274 0 $info->{data_type} = 'varchar';
275  
276 0 ▶ if (not $info->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info->{"size"}) 0 0 0
277 0 $info->{data_type} = 'text';
278 0 $info->{original}{data_type} = 'varchar';
279 }
280 }
281 elsif (lc($data_type) eq 'character') {
282 0 $info->{data_type} = 'char';
283 }
284 # DBD::Pg < 3.5.2 can get the order wrong on Pg >= 9.1.0
285 ▶ elsif (
Condition0%0/6
$DBD::Pg::VERSION >= "3.005002" || $self->dbh->{"pg_server_version"} < 90100 and my $values = $raw->{$col}{"pg_enum_values"}
!ll&&!rl&&r
000
$DBD::Pg::VERSION >= "3.005002" or $self->dbh->{"pg_server_version"} < 90100
l!l&&r!l&&!r
000
MC/DC0%0/3
$DBD::Pg::VERSION >= "3.005002" || $self->dbh->{"pg_server_version"} < 90100 and my $values = $raw->{$col}{"pg_enum_values"}
$DBD::Pg::VERSION >= "3.005002" $self->dbh->{"pg_server_version"} < 90100 my $values = $raw->{$col}{"pg_enum_values"}
Truth table0%0/5
A or B and C
A= $DBD::Pg::VERSION >= "3.005002"B= $self->dbh->{"pg_server_version"} < 90100C= my $values = $raw->{$col}{"pg_enum_values"}
ABCresult
00X0
1X00
0100
1X11
0111
286 ($DBD::Pg::VERSION >= 3.005002 or $self->dbh->{pg_server_version} < 90100)
287 and
288 my $values = $raw->{$col}->{pg_enum_values}
289 ) {
290 0 $info->{extra}{list} = $values;
291  
292 # Store its original name in extra for SQLT to pick up.
293 0 $info->{extra}{custom_type_name} = $info->{data_type};
294  
295 0 $info->{data_type} = 'enum';
296  
297 0 delete $info->{size};
298 }
299 else {
300 0 my ($typetype) = $self->schema->storage->dbh
301 ->selectrow_array(<<EOF, {}, $data_type);
302 SELECT typtype
303 FROM pg_catalog.pg_type
304 WHERE oid = ?::regtype
305 EOF
306 0 ▶ if ($typetype && $typetype eq 'e') {
Branch: 1 branch
BranchTrueFalseTotal
if ($typetype and $typetype eq "e") 0 0 0
Condition0%0/3
$typetype and $typetype eq "e"
!ll&&!rl&&r
000
MC/DC0%0/2
$typetype and $typetype eq "e"
$typetype $typetype eq "e"
Truth table0%0/3
A and B
A= $typetypeB= $typetype eq "e"
ABresult
0X0
100
111
307 # The following will extract a list of allowed values for the enum.
308 0 ▶ my $order_column = $self->dbh->{pg_server_version} >= 90100 ? 'enumsortorder' : 'oid';
Branch: 1 branch
BranchTrueFalseTotal
$self->dbh->{'pg_server_version'} >= 90100 ? : 0 0 0
309 0 $info->{extra}{list} = $self->dbh
310 ->selectcol_arrayref(<<EOF, {}, $data_type);
311 SELECT e.enumlabel
312 FROM pg_catalog.pg_enum e
313 WHERE e.enumtypid = ?::regtype
314 ORDER BY e.$order_column
315 EOF
316  
317 # Store its original name in extra for SQLT to pick up.
318 0 $info->{extra}{custom_type_name} = $data_type;
319  
320 0 $info->{data_type} = 'enum';
321  
322 0 delete $info->{size};
323 }
324 }
325  
326 0 ▶ if (ref($info->{default_value}) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info->{"default_value"} eq "SCALAR") 0 0 0
327 # process SERIAL columns
328 0 ▶ if (${ $info->{default_value} } =~ /\bnextval\('([^:]+)'/i) {
Branch: 3 branches
BranchTrueFalseTotal
if (${$info->{'default_value'};} =~ /\bnextval\('([^:]+)'/i) { } 0 0 0
elsif (lc ${$info->{'default_value'};} eq 'now()') { } 0 0 0
elsif (${$info->{'default_value'};} =~ /\bCURRENT_TIMESTAMP\b/) { } 0 0 0
329 0 $info->{is_auto_increment} = 1;
330 0 $info->{sequence} = $1;
331 0 delete $info->{default_value};
332 }
333 # alias now() to current_timestamp for deploying to other DBs
334 0 elsif (lc ${ $info->{default_value} } eq 'now()') {
335 # do not use a ref to a constant, that breaks Data::Dump output
336 0 ${$info->{default_value}} = 'current_timestamp';
337  
338 0 my $now = 'now()';
339 0 $info->{original}{default_value} = \$now;
340 }
341 0 elsif (${ $info->{default_value} } =~ /\bCURRENT_TIMESTAMP\b/) {
342 # PostgreSQL v10 upcases current_timestamp in default values
343 0 ${ $info->{default_value} } =~ s/\b(CURRENT_TIMESTAMP)\b/lc $1/ge;
344 }
345 }
346  
347 # detect 0/1 for booleans and rewrite
348 0 ▶ if ($data_type =~ /^bool/i && exists $info->{default_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type =~ /^bool/i and exists $info->{"default_value"}) 0 0 0
Condition0%0/3
$data_type =~ /^bool/i and exists $info->{"default_value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data_type =~ /^bool/i and exists $info->{"default_value"}
$data_type =~ /^bool/i exists $info->{"default_value"}
Truth table0%0/3
A and B
A= $data_type =~ /^bool/iB= exists $info->{"default_value"}
ABresult
0X0
100
111
349 0 ▶ if ($info->{default_value} eq '0') {
Branch: 2 branches
BranchTrueFalseTotal
if ($info->{'default_value'} eq '0') { } 0 0 0
elsif ($info->{'default_value'} eq '1') { } 0 0 0
350 0 my $false = 'false';
351 0 $info->{default_value} = \$false;
352 }
353 elsif ($info->{default_value} eq '1') {
354 0 my $true = 'true';
355 0 $info->{default_value} = \$true;
356 }
357 }
358 }
359  
360 0 return $result;
361 }
362  
363 sub _view_definition {
364 0 ▶ my ($self, $view) = @_;
Subroutine _view_definition: not called CC=1 SCAR=6.9
365  
366 0 my $def = $self->schema->storage->dbh->selectrow_array(<<'EOF', {}, $view->schema, $view->name);
367 SELECT pg_catalog.pg_get_viewdef(oid)
368 FROM pg_catalog.pg_class
369 WHERE relnamespace = (SELECT OID FROM pg_catalog.pg_namespace WHERE nspname = ?)
370 AND relname = ?
371 EOF
372 # The definition is returned as a complete statement including the
373 # trailing semicolon, but that's not allowed in CREATE VIEW, so
374 # strip it out
375 0 $def =~ s/\s*;\s*\z//;
376 0 return $def;
377 }
378  
379 =head1 SEE ALSO
380  
381 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
382 L<DBIx::Class::Schema::Loader::DBI>
383  
384 =head1 AUTHORS
385  
386 See L<DBIx::Class::Schema::Loader/AUTHORS>.
387  
388 =head1 LICENSE
389  
390 This library is free software; you can redistribute it and/or modify it under
391 the same terms as Perl itself.
392  
393 =cut
394  
395 1 1;
« blib/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm ↑ Summary blib/lib/DBIx/Class/Schema/Loader/DBI/ODBC/ACCESS.pm »