| 1 | package DBIO::DuckDB::Introspect; | ||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect a DuckDB database via information_schema + duckdb_* views | ||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 10 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use base 'DBIO::Introspect::Base'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use DBIO::DuckDB::Introspect::Tables; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use DBIO::DuckDB::Introspect::Columns; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use DBIO::DuckDB::Introspect::Indexes; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use DBIO::DuckDB::Introspect::ForeignKeys; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 10 | ▶ | use DBIO::DuckDB::Introspect::Uniques; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub schema { $_[0]->{schema} // 'main' } | ||||||||||||||||||||||||||||||||||
|
Subroutine
schema: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[0]{"schema"} // "main"
MC/DC0%0/1
$_[0]{"schema"} // "main"
$_[0]{"schema"}
Truth table0%0/2
A
A= $_[0]{"schema"}
| |||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub schemas { $_[0]->{schemas} || [] } | ||||||||||||||||||||||||||||||||||
|
Subroutine
schemas: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub catalog { $_[0]->{catalog} } | ||||||||||||||||||||||||||||||||||
|
Subroutine
catalog: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _build_model { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_build_model: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||
| 25 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 26 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||||||||||
| 27 | 0 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||
| 28 | 0 | my $catalog = $self->catalog; | |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $tables = DBIO::DuckDB::Introspect::Tables->fetch($dbh, $schema, $catalog); | |||||||||||||||||||||||||||||||||||
| 31 | 0 | my $columns = DBIO::DuckDB::Introspect::Columns->fetch($dbh, $schema, $tables, $catalog); | |||||||||||||||||||||||||||||||||||
| 32 | 0 | my $indexes = DBIO::DuckDB::Introspect::Indexes->fetch($dbh, $schema, $tables, $catalog); | |||||||||||||||||||||||||||||||||||
| 33 | 0 | my $fks = DBIO::DuckDB::Introspect::ForeignKeys->fetch($dbh, $schema, $tables, $catalog); | |||||||||||||||||||||||||||||||||||
| 34 | 0 | my $uniques = DBIO::DuckDB::Introspect::Uniques->fetch($dbh, $schema, $tables, $catalog); | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | 0 | my %model = ( | |||||||||||||||||||||||||||||||||||
| 37 | tables => $tables, | ||||||||||||||||||||||||||||||||||||
| 38 | columns => $columns, | ||||||||||||||||||||||||||||||||||||
| 39 | indexes => $indexes, | ||||||||||||||||||||||||||||||||||||
| 40 | foreign_keys => $fks, | ||||||||||||||||||||||||||||||||||||
| 41 | unique_constraints => $uniques, | ||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | # the schemas of the qualified sources, their tables keyed schema.table | ||||||||||||||||||||||||||||||||||||
| 45 | 0 | for my $ns (grep { $_ ne $schema } @{ $self->schemas }) { | |||||||||||||||||||||||||||||||||||
| 46 | 0 | my $t = DBIO::DuckDB::Introspect::Tables->fetch($dbh, $ns, $catalog); | |||||||||||||||||||||||||||||||||||
| 47 | 0 | my %part = ( | |||||||||||||||||||||||||||||||||||
| 48 | tables => $t, | ||||||||||||||||||||||||||||||||||||
| 49 | columns => DBIO::DuckDB::Introspect::Columns->fetch($dbh, $ns, $t, $catalog), | ||||||||||||||||||||||||||||||||||||
| 50 | indexes => DBIO::DuckDB::Introspect::Indexes->fetch($dbh, $ns, $t, $catalog), | ||||||||||||||||||||||||||||||||||||
| 51 | foreign_keys => DBIO::DuckDB::Introspect::ForeignKeys->fetch($dbh, $ns, $t, $catalog), | ||||||||||||||||||||||||||||||||||||
| 52 | unique_constraints => DBIO::DuckDB::Introspect::Uniques->fetch($dbh, $ns, $t, $catalog), | ||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||
| 54 | 0 | for my $kind (keys %part) { | |||||||||||||||||||||||||||||||||||
| 55 | 0 | for my $name (keys %{ $part{$kind} }) { | |||||||||||||||||||||||||||||||||||
| 56 | 0 | $model{$kind}{"$ns.$name"} = $part{$kind}{$name}; | |||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||
| 59 | 0 | $model{tables}{"$ns.$_"}{table_name} = "$ns.$_" for keys %$t; | |||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | 0 | return \%model; | |||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | sub table_columns_info { | ||||||||||||||||||||||||||||||||||
|
Subroutine
table_columns_info: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 67 | 3 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 3 | my %pk = map { $_ => 1 } @{ $self->table_pk_info($key) }; | |||||||||||||||||||||||||||||||||||
| 70 | 3 | my %info; | |||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | for my $col (@{ $self->model->{columns}{$key} || [] }) { | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->model->{'columns'}{$key} || []
MC/DC0%0/1
$self->model->{'columns'}{$key} || []
$self->model->{'columns'}{$key}
Truth table50%1/2
A
A= $self->model->{'columns'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 73 | 9 | my $name = $col->{column_name}; | |||||||||||||||||||||||||||||||||||
| 74 | # Core k126 (ADR 0038): the base folds is_pk into is_nullable so the | ||||||||||||||||||||||||||||||||||||
| 75 | # two contract methods cannot disagree about a key column. The DuckDB | ||||||||||||||||||||||||||||||||||||
| 76 | # model carries is_pk (Introspect/Columns.pm), and table_pk_info is | ||||||||||||||||||||||||||||||||||||
| 77 | # already consulted here for _normalize_default_value, so the fold is | ||||||||||||||||||||||||||||||||||||
| 78 | # one term in the same expression. | ||||||||||||||||||||||||||||||||||||
| 79 | 9 | ▶ | my $i = { is_nullable => (($col->{not_null} || $pk{$name}) ? 0 : 1) }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$col->{"not_null"} or $pk{$name}
MC/DC100%2/2
$col->{"not_null"} or $pk{$name}
$col->{"not_null"}
$pk{$name}
Truth table100%3/3
A or B
A= $col->{"not_null"}B= $pk{$name}
| |||||||||||||||||||||||||||||||||||||
| 80 | 9 | $self->_normalize_data_type($i, $col->{data_type}); | |||||||||||||||||||||||||||||||||||
| 81 | 9 | $self->_normalize_default_value($i, $col->{default_value}, $pk{$name}); | |||||||||||||||||||||||||||||||||||
| 82 | 9 | $info{$name} = $i; | |||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | 3 | return \%info; | |||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 9 | ▶ | sub _normalize_data_type { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_data_type: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 89 | 9 | my ($self, $info, $raw) = @_; | |||||||||||||||||||||||||||||||||||
| 90 | 9 | ▶ | my $type = defined $raw ? $raw : ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 91 | 9 | $type =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||
| 92 | 9 | $type =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | # DECIMAL(p,s) / NUMERIC(p,s) | ||||||||||||||||||||||||||||||||||||
| 95 | 9 | ▶ | if ($type =~ /^(decimal|numeric)\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\z/i) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 96 | 1 | $info->{data_type} = lc $1; | |||||||||||||||||||||||||||||||||||
| 97 | 1 | $info->{size} = [ 0 + $2, 0 + $3 ]; | |||||||||||||||||||||||||||||||||||
| 98 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | # VARCHAR(n) / CHAR(n) / DECIMAL(p) etc. | ||||||||||||||||||||||||||||||||||||
| 102 | 8 | ▶ | if ($type =~ /^([A-Za-z][\w ]*?)\s*\(\s*(\d+)\s*\)\z/) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 103 | 1 | $info->{data_type} = lc $1; | |||||||||||||||||||||||||||||||||||
| 104 | 1 | $info->{size} = 0 + $2; | |||||||||||||||||||||||||||||||||||
| 105 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | 7 | $info->{data_type} = lc $type; | |||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | 9 | ▶ | sub _normalize_default_value { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_default_value: called CC=11 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||
| 112 | 9 | my ($self, $info, $default, $is_pk) = @_; | |||||||||||||||||||||||||||||||||||
| 113 | 9 | ▶ | return unless defined $default; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | 4 | my $value = $default; | |||||||||||||||||||||||||||||||||||
| 116 | 4 | $value =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||
| 117 | 4 | $value =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | # Auto-increment: DEFAULT nextval('seq') | ||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | if ($value =~ /\bnextval\(\s*'?"?([^'")]+)"?'?\s*\)/i) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 121 | 1 | $info->{is_auto_increment} = 1; | |||||||||||||||||||||||||||||||||||
| 122 | 1 | $info->{sequence} = $1; | |||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | $info->{retrieve_on_insert} = 1 if $is_pk; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 124 | 1 | return; | |||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | # String literal, optionally CAST(...) | ||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | if ($value =~ /^CAST\(\s*'(.*?)'\s+AS\s+[\w ]+\)\z/is | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$value =~ /^CAST\(\s*'(.*?)'\s+AS\s+[\w ]+\)\z/is or $value =~ /^'(.*?)'(?:::[\w ]+)?\z/s
MC/DC50%1/2
$value =~ /^CAST\(\s*'(.*?)'\s+AS\s+[\w ]+\)\z/is or $value =~ /^'(.*?)'(?:::[\w ]+)?\z/s
$value =~ /^CAST\(\s*'(.*?)'\s+AS\s+[\w ]+\)\z/is
$value =~ /^'(.*?)'(?:::[\w ]+)?\z/s
Truth table66%2/3
A or B
A= $value =~ /^CAST\(\s*'(.*?)'\s+AS\s+[\w ]+\)\z/isB= $value =~ /^'(.*?)'(?:::[\w ]+)?\z/s
| |||||||||||||||||||||||||||||||||||||
| 129 | || $value =~ /^'(.*?)'(?:::[\w ]+)?\z/s) { | ||||||||||||||||||||||||||||||||||||
| 130 | 1 | $info->{default_value} = $1; | |||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||
| 132 | # Bare number | ||||||||||||||||||||||||||||||||||||
| 133 | elsif ($value =~ /^-?\d+(?:\.\d+)?\z/) { | ||||||||||||||||||||||||||||||||||||
| 134 | 1 | $info->{default_value} = $value; | |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||
| 136 | # NULL | ||||||||||||||||||||||||||||||||||||
| 137 | elsif ($value =~ /^NULL\z/i) { | ||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $null = 'null'; | |||||||||||||||||||||||||||||||||||
| 139 | 0 | $info->{default_value} = \$null; | |||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||
| 141 | # Function / keyword literal (CURRENT_TIMESTAMP, now(), ...) | ||||||||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | my $literal = lc($value) eq 'now()' ? 'current_timestamp' : $value; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 144 | 1 | $info->{default_value} = \$literal; | |||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | $info->{retrieve_on_insert} = 1 if $is_pk && !$info->{is_auto_increment}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$is_pk and not $info->{"is_auto_increment"}
MC/DC0%0/2
$is_pk and not $info->{"is_auto_increment"}
$is_pk
not $info->{"is_auto_increment"}
Truth table33%1/3
A and not(B)
A= $is_pkB= not $info->{"is_auto_increment"}
| |||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub table_uniq_info { | ||||||||||||||||||||||||||||||||||
|
Subroutine
table_uniq_info: called CC=10 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 152 | 1 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | my $indexes = $self->model->{indexes}{$key} || {}; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->model->{'indexes'}{$key} || {}
MC/DC0%0/1
$self->model->{'indexes'}{$key} || {}
$self->model->{'indexes'}{$key}
Truth table50%1/2
A
A= $self->model->{'indexes'}{$key}
| |||||||||||||||||||||||||||||||||||||
| 154 | 1 | my @uniq; | |||||||||||||||||||||||||||||||||||
| 155 | 1 | for my $name (sort keys %$indexes) { | |||||||||||||||||||||||||||||||||||
| 156 | 3 | my $idx = $indexes->{$name}; | |||||||||||||||||||||||||||||||||||
| 157 | 3 | ▶ | next unless $idx->{is_unique}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | next if $idx->{partial}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | next unless @{ $idx->{columns} || [] }; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$idx->{'columns'} || []
MC/DC0%0/1
$idx->{'columns'} || []
$idx->{'columns'}
Truth table50%1/2
A
A= $idx->{'columns'}
| |||||||||||||||||||||||||||||||||||||
| 160 | 1 | push @uniq, [ $name => $idx->{columns} ]; | |||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||
| 163 | # An introspector built from a model alone has no connection to ask. | ||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | return \@uniq unless $self->dbh; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $sql = q{ | |||||||||||||||||||||||||||||||||||
| 167 | SELECT constraint_name, constraint_column_names | ||||||||||||||||||||||||||||||||||||
| 168 | FROM duckdb_constraints() | ||||||||||||||||||||||||||||||||||||
| 169 | WHERE schema_name = ? AND table_name = ? AND constraint_type = 'UNIQUE' | ||||||||||||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||||||||||
| 171 | 0 | my @bind = ($self->schema, $key); | |||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if (defined $self->catalog) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 173 | 0 | $sql .= q{ AND database_name = ?}; | |||||||||||||||||||||||||||||||||||
| 174 | 0 | push @bind, $self->catalog; | |||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||
| 176 | 0 | $sql .= q{ ORDER BY constraint_name}; | |||||||||||||||||||||||||||||||||||
| 177 | 0 | my $sth = $self->dbh->prepare($sql); | |||||||||||||||||||||||||||||||||||
| 178 | 0 | $sth->execute(@bind); | |||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | while (my ($name, $cols) = $sth->fetchrow_array) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 180 | 0 | push @uniq, [ $name => [ @$cols ] ]; | |||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | 0 | return \@uniq; | |||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub view_definition { | ||||||||||||||||||||||||||||||||||
|
Subroutine
view_definition: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 188 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return undef unless $self->table_is_view($key); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $sql = q{ | |||||||||||||||||||||||||||||||||||
| 192 | SELECT view_definition | ||||||||||||||||||||||||||||||||||||
| 193 | FROM information_schema.views | ||||||||||||||||||||||||||||||||||||
| 194 | WHERE table_schema = ? AND table_name = ? | ||||||||||||||||||||||||||||||||||||
| 195 | }; | ||||||||||||||||||||||||||||||||||||
| 196 | 0 | my @bind = ($self->schema, $key); | |||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if (defined $self->catalog) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 198 | 0 | $sql .= q{ AND table_catalog = ?}; | |||||||||||||||||||||||||||||||||||
| 199 | 0 | push @bind, $self->catalog; | |||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||
| 202 | 0 | my ($def) = $self->dbh->selectrow_array($sql, undef, @bind); | |||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | return undef unless defined $def; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 204 | 0 | $def =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||
| 205 | 0 | $def =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||
| 206 | 0 | $def =~ s/\s*;\s*\z//; | |||||||||||||||||||||||||||||||||||
| 207 | 0 | return $def; | |||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||
| 210 | 10 | 1; | |||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||
| 212 | __END__ | ||||||||||||||||||||||||||||||||||||