« blib/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm
↑ Summary
blib/lib/DBIx/Class/Schema/Loader/DBI/InterBase.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.07053'; | |||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _setup { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $self->{db_schema} ||= ['public']; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"db_schema"} ||= ["public"]
MC/DC0%0/1
$self->{"db_schema"} ||= ["public"]
$self->{"db_schema"}
Truth table0%0/2
A
A= $self->{"db_schema"}
| |||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( not defined $self->preserve_case ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _system_schemas { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_system_schemas: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _table_fk_info { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_fk_info: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ( $self, $table ) = @_; | |||||||||||||||||||||||||||||||||||||
| 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 ( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 83 | my ( | ||||||||||||||||||||||||||||||||||||||
| 84 | $fk, $remote_schema, $remote_table, $col, | ||||||||||||||||||||||||||||||||||||||
| 85 | $remote_col, $delete_rule, $update_rule, $is_deferrable | ||||||||||||||||||||||||||||||||||||||
| 86 | ) | ||||||||||||||||||||||||||||||||||||||
| 87 | = $sth->fetchrow_array | ||||||||||||||||||||||||||||||||||||||
| 88 | ) | ||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||
| 90 | 0 | push @{ $rels{$fk}{local_columns} }, $self->_lc($col); | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | push @{ $rels{$fk}{remote_columns} }, $self->_lc($remote_col); | |||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | $rels{$fk}{remote_table} = DBIx::Class::Schema::Loader::Table->new( | ||||||||||||||||||||||||||||||||||||||
| 94 | loader => $self, | ||||||||||||||||||||||||||||||||||||||
| 95 | name => $remote_table, | ||||||||||||||||||||||||||||||||||||||
| 96 | schema => $remote_schema, | ||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | ) unless exists $rels{$fk}{remote_table}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | $rels{$fk}{attrs} ||= { | ||||||||||||||||||||||||||||||||||||||
| 100 | on_delete => $pg_rules{$delete_rule}, | ||||||||||||||||||||||||||||||||||||||
| 101 | 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}
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"}
| |||||||||||||||||||||||||||||||||||||||
| 102 | is_deferrable => $is_deferrable, | ||||||||||||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return [ map { $rels{$_} } sort keys %rels ]; | |||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub _table_uniq_info { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_uniq_info: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ( $self, $table ) = @_; | |||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | # Use the default support if available | ||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $self->next::method($table) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 114 | if $DBD::Pg::VERSION >= 1.50; | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my @uniqs; | |||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | # Most of the SQL here is mostly based on | ||||||||||||||||||||||||||||||||||||||
| 119 | # Rose::DB::Object::Metadata::Auto::Pg, after some prodding from | ||||||||||||||||||||||||||||||||||||||
| 120 | # John Siracusa to use his superior SQL code :) | ||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | 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 = ?")
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 = ?")
| |||||||||||||||||||||||||||||||||||||||
| 123 | q{SELECT attname FROM pg_catalog.pg_attribute | ||||||||||||||||||||||||||||||||||||||
| 124 | WHERE attrelid = ? AND attnum = ?} | ||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||
| 127 | 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")
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")
| |||||||||||||||||||||||||||||||||||||||
| 128 | q{SELECT x.indrelid, i.relname, x.indkey | ||||||||||||||||||||||||||||||||||||||
| 129 | FROM | ||||||||||||||||||||||||||||||||||||||
| 130 | pg_catalog.pg_index x | ||||||||||||||||||||||||||||||||||||||
| 131 | JOIN pg_catalog.pg_class c ON c.oid = x.indrelid | ||||||||||||||||||||||||||||||||||||||
| 132 | JOIN pg_catalog.pg_class i ON i.oid = x.indexrelid | ||||||||||||||||||||||||||||||||||||||
| 133 | JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | ||||||||||||||||||||||||||||||||||||||
| 134 | WHERE | ||||||||||||||||||||||||||||||||||||||
| 135 | x.indisunique = 't' AND | ||||||||||||||||||||||||||||||||||||||
| 136 | x.indpred IS NULL AND | ||||||||||||||||||||||||||||||||||||||
| 137 | c.relkind = 'r' AND | ||||||||||||||||||||||||||||||||||||||
| 138 | i.relkind = 'i' AND | ||||||||||||||||||||||||||||||||||||||
| 139 | n.nspname = ? AND | ||||||||||||||||||||||||||||||||||||||
| 140 | c.relname = ? | ||||||||||||||||||||||||||||||||||||||
| 141 | ORDER BY i.relname} | ||||||||||||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $uniq_sth->execute( $table->schema, $table->name ); | |||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | while ( my $row = $uniq_sth->fetchrow_arrayref ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my ( $tableid, $indexname, $col_nums ) = @$row; | |||||||||||||||||||||||||||||||||||||
| 147 | 0 | $col_nums =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||
| 148 | 0 | my @col_nums = split( /\s+/, $col_nums ); | |||||||||||||||||||||||||||||||||||||
| 149 | 0 | my @col_names; | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | foreach (@col_nums) { | |||||||||||||||||||||||||||||||||||||
| 152 | 0 | $attr_sth->execute( $tableid, $_ ); | |||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $name_aref = $attr_sth->fetchrow_arrayref; | |||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | push( @col_names, $self->_lc( $name_aref->[0] ) ) if $name_aref; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | # skip indexes with missing column names (e.g. expression indexes) | ||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ( @col_names == @col_nums ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 159 | 0 | push( @uniqs, [ $indexname => \@col_names ] ); | |||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return \@uniqs; | |||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub _table_comment { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_comment: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 168 | 0 | my ($table) = @_; | |||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $table_comment = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return $table_comment if $table_comment; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ($table_comment) = | |||||||||||||||||||||||||||||||||||||
| 175 | $self->dbh->selectrow_array( <<'EOF', {}, $table->name, $table->schema ); | ||||||||||||||||||||||||||||||||||||||
| 176 | SELECT pg_catalog.obj_description(oid) | ||||||||||||||||||||||||||||||||||||||
| 177 | FROM pg_catalog.pg_class | ||||||||||||||||||||||||||||||||||||||
| 178 | WHERE relname=? AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=?) | ||||||||||||||||||||||||||||||||||||||
| 179 | EOF | ||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return $table_comment; | |||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub _column_comment { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_column_comment: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 186 | 0 | my ( $table, $column_number, $column_name ) = @_; | |||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $column_comment = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return $column_comment if $column_comment; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return $self->dbh->selectrow_array( | |||||||||||||||||||||||||||||||||||||
| 193 | <<'EOF', {}, $column_number, $table->name, $table->schema ); | ||||||||||||||||||||||||||||||||||||||
| 194 | SELECT pg_catalog.col_description(oid, ?) | ||||||||||||||||||||||||||||||||||||||
| 195 | FROM pg_catalog.pg_class | ||||||||||||||||||||||||||||||||||||||
| 196 | WHERE relname=? AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=?) | ||||||||||||||||||||||||||||||||||||||
| 197 | EOF | ||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||
| 200 | # Make sure data_type's that don't need it don't have a 'size' column_info, and | ||||||||||||||||||||||||||||||||||||||
| 201 | # set the correct precision for datetime and varbit types. | ||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub _columns_info_for { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_columns_info_for: not called CC=41 SCAR=74.5
| |||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($table) = @_; | |||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ( $result, $raw ) = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||
| 207 | 0 | my %pkeys; | |||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | while ( my ( $col, $info ) = each %$result ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $data_type = $info->{data_type}; | |||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||
| 212 | # these types are fixed size | ||||||||||||||||||||||||||||||||||||||
| 213 | # XXX should this be a negative match? | ||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ( $data_type =~ | ||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||
| 215 | /^(?: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 | ||||||||||||||||||||||||||||||||||||||
| 216 | ) | ||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||
| 218 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | # for datetime types, check if it has a precision or not | ||||||||||||||||||||||||||||||||||||||
| 222 | elsif ( $data_type =~ /^(?:interval|time|timestamp)\b/i ) { | ||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ( lc($data_type) eq 'timestamp without time zone' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $info->{data_type} = 'timestamp'; | |||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||
| 226 | elsif ( lc($data_type) eq 'time without time zone' ) { | ||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $info->{data_type} = 'time'; | |||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ($precision) = $self->schema->storage->dbh->selectrow_array( | |||||||||||||||||||||||||||||||||||||
| 231 | <<EOF, {}, $table->name, $col ); | ||||||||||||||||||||||||||||||||||||||
| 232 | SELECT datetime_precision | ||||||||||||||||||||||||||||||||||||||
| 233 | FROM information_schema.columns | ||||||||||||||||||||||||||||||||||||||
| 234 | WHERE table_name = ? and column_name = ? | ||||||||||||||||||||||||||||||||||||||
| 235 | EOF | ||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ( $data_type =~ /^time\b/i ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( ( not defined $precision ) || $precision !~ /^\d/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $precision && $precision =~ /^\d/
MC/DC0%0/2
defined $precision && $precision =~ /^\d/
defined $precision
$precision =~ /^\d/
Truth table0%0/3
A && B
A= defined $precisionB= $precision =~ /^\d/
| |||||||||||||||||||||||||||||||||||||||
| 239 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my ($integer_datetimes) = | |||||||||||||||||||||||||||||||||||||
| 243 | $self->dbh->selectrow_array('show integer_datetimes'); | ||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $max_precision = $integer_datetimes =~ /^on\z/i ? 6 : 10; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ( $precision == $max_precision ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 248 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||
| 250 | else { | ||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $info->{size} = $precision; | |||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||
| 255 | ▶ | elsif ( ( not defined $precision ) | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
not defined $precision && $precision =~ /^\d/ or $precision == 6
defined $precision && $precision =~ /^\d/
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
| |||||||||||||||||||||||||||||||||||||||
| 256 | || $precision !~ /^\d/ | ||||||||||||||||||||||||||||||||||||||
| 257 | || $precision == 6 ) | ||||||||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||||||
| 259 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||
| 261 | else { | ||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $info->{size} = $precision; | |||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||
| 265 | elsif ( $data_type =~ /^(?:bit(?: varying)?|varbit)\z/i ) { | ||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $info->{data_type} = 'varbit' if $data_type =~ /var/i; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my ($precision) = | |||||||||||||||||||||||||||||||||||||
| 269 | $self->dbh->selectrow_array( <<EOF, {}, $table->name, $col ); | ||||||||||||||||||||||||||||||||||||||
| 270 | SELECT character_maximum_length | ||||||||||||||||||||||||||||||||||||||
| 271 | FROM information_schema.columns | ||||||||||||||||||||||||||||||||||||||
| 272 | WHERE table_name = ? and column_name = ? | ||||||||||||||||||||||||||||||||||||||
| 273 | EOF | ||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $info->{size} = $precision if $precision; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $info->{size} = 1 if ( not $precision ) && lc($data_type) eq 'bit'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $precision and lc $data_type eq "bit"
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"
| |||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||
| 279 | ▶ | elsif ( $data_type =~ /^(?:numeric|decimal)\z/i | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$data_type =~ /^(?:numeric|decimal)\z/i and my $size = $info->{"size"}
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"}
| |||||||||||||||||||||||||||||||||||||||
| 280 | && ( my $size = $info->{size} ) ) | ||||||||||||||||||||||||||||||||||||||
| 281 | { | ||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $size =~ s/\s*//g; | |||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ( $scale, $precision ) = split /,/, $size; | |||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $info->{size} = [ $precision, $scale ]; | |||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||
| 288 | elsif ( lc($data_type) eq 'character varying' ) { | ||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $info->{data_type} = 'varchar'; | |||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ( not $info->{size} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $info->{data_type} = 'text'; | |||||||||||||||||||||||||||||||||||||
| 293 | 0 | $info->{original}{data_type} = 'varchar'; | |||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||
| 296 | elsif ( lc($data_type) eq 'character' ) { | ||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $info->{data_type} = 'char'; | |||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | # DBD::Pg < 3.5.2 can get the order wrong on Pg >= 9.1.0 | ||||||||||||||||||||||||||||||||||||||
| 301 | ▶ | elsif ( | |||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$DBD::Pg::VERSION >= "3.005002" || $self->dbh->{"pg_server_version"} < 90100 and my $values = $raw->{$col}{"pg_enum_values"}
$DBD::Pg::VERSION >= "3.005002" or $self->dbh->{"pg_server_version"} < 90100
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"}
| |||||||||||||||||||||||||||||||||||||||
| 302 | ( | ||||||||||||||||||||||||||||||||||||||
| 303 | $DBD::Pg::VERSION >= 3.005002 | ||||||||||||||||||||||||||||||||||||||
| 304 | or $self->dbh->{pg_server_version} < 90100 | ||||||||||||||||||||||||||||||||||||||
| 305 | ) | ||||||||||||||||||||||||||||||||||||||
| 306 | and my $values = $raw->{$col}->{pg_enum_values} | ||||||||||||||||||||||||||||||||||||||
| 307 | ) | ||||||||||||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $info->{extra}{list} = $values; | |||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||
| 311 | # Store its original name in extra for SQLT to pick up. | ||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $info->{extra}{custom_type_name} = $info->{data_type}; | |||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $info->{data_type} = 'enum'; | |||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||
| 316 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||
| 318 | else { | ||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my ($typetype) = | |||||||||||||||||||||||||||||||||||||
| 320 | $self->schema->storage->dbh->selectrow_array( <<EOF, {}, $data_type ); | ||||||||||||||||||||||||||||||||||||||
| 321 | SELECT typtype | ||||||||||||||||||||||||||||||||||||||
| 322 | FROM pg_catalog.pg_type | ||||||||||||||||||||||||||||||||||||||
| 323 | WHERE oid = ?::regtype | ||||||||||||||||||||||||||||||||||||||
| 324 | EOF | ||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ( $typetype && $typetype eq 'e' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$typetype and $typetype eq "e"
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"
| |||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||
| 327 | # The following will extract a list of allowed values for the enum. | ||||||||||||||||||||||||||||||||||||||
| 328 | my $order_column = | ||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | $self->dbh->{pg_server_version} >= 90100 ? 'enumsortorder' : 'oid'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 330 | $info->{extra}{list} = | ||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->dbh->selectcol_arrayref( <<EOF, {}, $data_type ); | |||||||||||||||||||||||||||||||||||||
| 332 | SELECT e.enumlabel | ||||||||||||||||||||||||||||||||||||||
| 333 | FROM pg_catalog.pg_enum e | ||||||||||||||||||||||||||||||||||||||
| 334 | WHERE e.enumtypid = ?::regtype | ||||||||||||||||||||||||||||||||||||||
| 335 | ORDER BY e.$order_column | ||||||||||||||||||||||||||||||||||||||
| 336 | EOF | ||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||
| 338 | # Store its original name in extra for SQLT to pick up. | ||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $info->{extra}{custom_type_name} = $data_type; | |||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $info->{data_type} = 'enum'; | |||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ( ref( $info->{default_value} ) eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | # process SERIAL columns | ||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ( ${ $info->{default_value} } =~ /\bnextval\('([^:]+)'/i ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $info->{is_auto_increment} = 1; | |||||||||||||||||||||||||||||||||||||
| 352 | 0 | $info->{sequence} = $1; | |||||||||||||||||||||||||||||||||||||
| 353 | 0 | delete $info->{default_value}; | |||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||
| 356 | # alias now() to current_timestamp for deploying to other DBs | ||||||||||||||||||||||||||||||||||||||
| 357 | 0 | elsif ( lc ${ $info->{default_value} } eq 'now()' ) { | |||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | # do not use a ref to a constant, that breaks Data::Dump output | ||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ${ $info->{default_value} } = 'current_timestamp'; | |||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my $now = 'now()'; | |||||||||||||||||||||||||||||||||||||
| 363 | 0 | $info->{original}{default_value} = \$now; | |||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||
| 365 | 0 | elsif ( ${ $info->{default_value} } =~ /\bCURRENT_TIMESTAMP\b/ ) { | |||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||
| 367 | # PostgreSQL v10 upcases current_timestamp in default values | ||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ${ $info->{default_value} } =~ s/\b(CURRENT_TIMESTAMP)\b/lc $1/ge; | |||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||
| 371 | # if there's a default value + it's a primary key, set to retrieve the default | ||||||||||||||||||||||||||||||||||||||
| 372 | # on insert even if it's not serial specifically | ||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ( !$info->{is_auto_increment} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | %pkeys = map { $_ => 1 } @{ $self->_table_pk_info($table) } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 375 | unless %pkeys; | ||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ( $pkeys{$col} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $info->{retrieve_on_insert} = 1; | |||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||
| 383 | # detect 0/1 for booleans and rewrite | ||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ( $data_type =~ /^bool/i && exists $info->{default_value} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$data_type =~ /^bool/i and exists $info->{"default_value"}
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"}
| |||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ( $info->{default_value} eq '0' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $false = 'false'; | |||||||||||||||||||||||||||||||||||||
| 387 | 0 | $info->{default_value} = \$false; | |||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||
| 389 | elsif ( $info->{default_value} eq '1' ) { | ||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $true = 'true'; | |||||||||||||||||||||||||||||||||||||
| 391 | 0 | $info->{default_value} = \$true; | |||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub _view_definition { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_view_definition: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my ( $self, $view ) = @_; | |||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $def = $self->schema->storage->dbh->selectrow_array( | |||||||||||||||||||||||||||||||||||||
| 403 | <<'EOF', {}, $view->schema, $view->name ); | ||||||||||||||||||||||||||||||||||||||
| 404 | SELECT pg_catalog.pg_get_viewdef(oid) | ||||||||||||||||||||||||||||||||||||||
| 405 | FROM pg_catalog.pg_class | ||||||||||||||||||||||||||||||||||||||
| 406 | WHERE relnamespace = (SELECT OID FROM pg_catalog.pg_namespace WHERE nspname = ?) | ||||||||||||||||||||||||||||||||||||||
| 407 | AND relname = ? | ||||||||||||||||||||||||||||||||||||||
| 408 | EOF | ||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||
| 410 | # The definition is returned as a complete statement including the | ||||||||||||||||||||||||||||||||||||||
| 411 | # trailing semicolon, but that's not allowed in CREATE VIEW, so | ||||||||||||||||||||||||||||||||||||||
| 412 | # strip it out | ||||||||||||||||||||||||||||||||||||||
| 413 | 0 | $def =~ s/\s*;\s*\z//; | |||||||||||||||||||||||||||||||||||||
| 414 | 0 | return $def; | |||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||
| 417 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||
| 419 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, | ||||||||||||||||||||||||||||||||||||||
| 420 | L<DBIx::Class::Schema::Loader::DBI> | ||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||
| 422 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||
| 424 | See L<DBIx::Class::Schema::Loader/AUTHORS>. | ||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||
| 426 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||
| 428 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||
| 429 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||
| 431 | =cut | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | 1 | 1; | |||||||||||||||||||||||||||||||||||||