« blib/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm
↑ Summary
blib/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm »
| 1 | package DBIx::Class::Schema::Loader::DBI::mysql; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp::Clan qw/^DBIx::Class/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use List::Util qw/any first/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use DBIx::Class::Schema::Loader::Table (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.07053'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | DBIx::Class::Schema::Loader::DBI::mysql - DBIx::Class::Schema::Loader::DBI mysql Implementation. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub _setup { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $self->schema->storage->sql_maker->quote_char("`"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->schema->storage->sql_maker->name_sep("."); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if (not defined $self->preserve_case) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->preserve_case(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($self->db_schema && $self->db_schema->[0] eq '%') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->db_schema and $self->db_schema->[0] eq "%"
MC/DC0%0/2
$self->db_schema and $self->db_schema->[0] eq "%"
$self->db_schema
$self->db_schema->[0] eq "%"
Truth table0%0/3
A and B
A= $self->db_schemaB= $self->db_schema->[0] eq "%"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my @schemas = try { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self->_show_databases; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | croak "no SHOW DATABASES privileges: $_"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | @schemas = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $schema = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | not any { lc($schema) eq lc($_) } $self->_system_schemas | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } @schemas; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $self->db_schema(\@schemas); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _show_databases { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_databases: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return map $_->[0], @{ $self->dbh->selectall_arrayref('SHOW DATABASES') }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _system_schemas { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_system_schemas: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return ($self->next::method(@_), 'mysql'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub _table_fk_info { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_fk_info: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($self, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $table_def_ref = eval { $self->dbh->selectrow_arrayref("SHOW CREATE TABLE ".$table->sql_name) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $table_def = $table_def_ref->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return [] if not $table_def; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $qt = qr/["`]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $nqt = qr/[^"`]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my (@reldata) = ($table_def =~ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | /CONSTRAINT ${qt}${nqt}+${qt} FOREIGN KEY \($qt(.*)$qt\) REFERENCES (?:$qt($nqt+)$qt\.)?$qt($nqt+)$qt \($qt(.+)$qt\)\s*(.*)/ig | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my @rels; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | while (scalar @reldata > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($cols, $f_schema, $f_table, $f_cols, $rest) = splice @reldata, 0, 5; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my @cols = map { s/$qt//g; $self->_lc($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | split(/$qt?\s*$qt?,$qt?\s*$qt?/, $cols); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my @f_cols = map { s/$qt//g; $self->_lc($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | split(/$qt?\s*$qt?,$qt?\s*$qt?/, $f_cols); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Match case of remote schema to that in SHOW DATABASES, if it's there | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # and we have permissions to run SHOW DATABASES. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($f_schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $matched = first { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | lc($_) eq lc($f_schema) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | } try { $self->_show_databases }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $f_schema = $matched if $matched; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $remote_table = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Get ->tables_list to return tables from the remote schema, in case it is not in the db_schema list. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | local $self->{db_schema} = [ $f_schema ] if $f_schema; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | first { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | lc($_->name) eq lc($f_table) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
lc $_->name eq lc $f_table && (!$f_schema || lc $_->schema eq lc $f_schema)
not $f_schema or lc $_->schema eq lc $f_schema
MC/DC0%0/3
lc $_->name eq lc $f_table && (!$f_schema || lc $_->schema eq lc $f_schema)
lc $_->name eq lc $f_table
not $f_schema
lc $_->schema eq lc $f_schema
Truth table0%0/4
A && not(B) or C
A= lc $_->name eq lc $f_tableB= not $f_schemaC= lc $_->schema eq lc $f_schema
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | && ((not $f_schema) || lc($_->schema) eq lc($f_schema)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | } $self->_tables_list; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # The table may not be in any database, or it may not have been found by the previous code block for whatever reason. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (not $remote_table) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $remote_schema = $f_schema || $self->db_schema && @{ $self->db_schema } == 1 && $self->db_schema->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$f_schema || $self->db_schema && @{$self->db_schema;} == 1 && $self->db_schema->[0]
$self->db_schema and @{$self->db_schema;} == 1 and $self->db_schema->[0]
$self->db_schema and @{$self->db_schema;} == 1
MC/DC0%0/4
$f_schema || $self->db_schema && @{$self->db_schema;} == 1 && $self->db_schema->[0]
$f_schema
$self->db_schema
@{$self->db_schema;} == 1
$self->db_schema->[0]
Truth table0%0/5
A || B and C and D
A= $f_schemaB= $self->db_schemaC= @{$self->db_schema;} == 1D= $self->db_schema->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $remote_table = DBIx::Class::Schema::Loader::Table->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | loader => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | name => $f_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ($remote_schema ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | schema => $remote_schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my %attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($rest) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my @on_clauses = $rest =~ /(ON DELETE|ON UPDATE) (RESTRICT|CASCADE|SET NULL|NO ACTION) ?/ig; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | while (my ($clause, $value) = splice @on_clauses, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $clause = lc $clause; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $clause =~ s/ /_/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $value = uc $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $attrs{$clause} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # The default behavior is RESTRICT. Specifying RESTRICT explicitly just removes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # that ON clause from the SHOW CREATE TABLE output. For this reason, even | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # though the default for these clauses everywhere else in Schema::Loader is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # CASCADE, we change the default here to RESTRICT in order to reproduce the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # schema faithfully. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $attrs{on_delete} ||= 'RESTRICT'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attrs{"on_delete"} ||= "RESTRICT"
MC/DC0%0/1
$attrs{"on_delete"} ||= "RESTRICT"
$attrs{"on_delete"}
Truth table0%0/2
A
A= $attrs{"on_delete"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $attrs{on_update} ||= 'RESTRICT'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attrs{"on_update"} ||= "RESTRICT"
MC/DC0%0/1
$attrs{"on_update"} ||= "RESTRICT"
$attrs{"on_update"}
Truth table0%0/2
A
A= $attrs{"on_update"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # MySQL does not have a DEFERRABLE attribute, but there is a way to defer FKs. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $attrs{is_deferrable} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | push(@rels, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | local_columns => \@cols, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | remote_columns => \@f_cols, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | remote_table => $remote_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | attrs => \%attrs, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return \@rels; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # primary and unique info comes from the same sql statement, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # so cache it here for both routines to use | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub _mysql_table_get_keys { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mysql_table_get_keys: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my ($self, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if(!exists($self->{_cache}->{_mysql_keys}->{$table->sql_name})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my %keydata; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $sth = $self->dbh->prepare('SHOW INDEX FROM '.$table->sql_name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | while(my $row = $sth->fetchrow_hashref) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | next if $row->{Non_unique}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | push(@{$keydata{$row->{Key_name}}}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | [ $row->{Seq_in_index}, $self->_lc($row->{Column_name}) ] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | foreach my $keyname (keys %keydata) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | @{$keydata{$keyname}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $keydata{$keyname} = \@ordered_cols; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->{_cache}->{_mysql_keys}->{$table->sql_name} = \%keydata; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return $self->{_cache}->{_mysql_keys}->{$table->sql_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub _table_pk_info { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_pk_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my ( $self, $table ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return $self->_mysql_table_get_keys($table)->{PRIMARY}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub _table_uniq_info { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_uniq_info: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my ( $self, $table ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my @uniqs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $keydata = $self->_mysql_table_get_keys($table); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | foreach my $keyname (sort keys %$keydata) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | next if $keyname eq 'PRIMARY'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | push(@uniqs, [ $keyname => $keydata->{$keyname} ]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | return \@uniqs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub _columns_info_for { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_columns_info_for: not called CC=30 SCAR=68.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my ($table) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $result = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | while (my ($col, $info) = each %$result) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($info->{data_type} eq 'int') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $info->{data_type} = 'integer'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | elsif ($info->{data_type} eq 'double') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $info->{data_type} = 'double precision'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $data_type = $info->{data_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | delete $info->{size} if $data_type !~ /^(?: (?:var)?(?:char(?:acter)?|binary) | bit | year)\z/ix; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # information_schema is available in 5.0+ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my ($precision, $scale, $column_type, $default) = eval { $self->dbh->selectrow_array(<<'EOF', {}, $table->name, lc($col)) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | SELECT numeric_precision, numeric_scale, column_type, column_default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | FROM information_schema.columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | WHERE table_schema = schema() AND table_name = ? AND lower(column_name) = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $has_information_schema = not $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $column_type = '' if not defined $column_type; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ($data_type eq 'bit' && (not exists $info->{size})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition0%0/3
$data_type eq "bit" and not exists $info->{"size"}
MC/DC0%0/2
$data_type eq "bit" and not exists $info->{"size"}
$data_type eq "bit"
not exists $info->{"size"}
Truth table0%0/3
A and not(B)
A= $data_type eq "bit"B= not exists $info->{"size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | $info->{size} = $precision if defined $precision; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | elsif ($data_type =~ /^(?:float|double precision|decimal)\z/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if (defined $precision && defined $scale) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $precision and defined $scale
MC/DC0%0/2
defined $precision and defined $scale
defined $precision
defined $scale
Truth table0%0/3
A and B
A= defined $precisionB= defined $scale
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($precision == 10 && $scale == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision == 10 and $scale == 0
MC/DC0%0/2
$precision == 10 and $scale == 0
$precision == 10
$scale == 0
Truth table0%0/3
A and B
A= $precision == 10B= $scale == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $info->{size} = [$precision,$scale]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | elsif ($data_type eq 'year') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($column_type =~ /\(2\)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $info->{size} = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ▶ | elsif ($column_type =~ /\(4\)/ || $info->{size} == 4) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$column_type =~ /\(4\)/ or $info->{"size"} == 4
MC/DC0%0/2
$column_type =~ /\(4\)/ or $info->{"size"} == 4
$column_type =~ /\(4\)/
$info->{"size"} == 4
Truth table0%0/3
A or B
A= $column_type =~ /\(4\)/B= $info->{"size"} == 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | delete $info->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | elsif ($data_type =~ /^(?:date(?:time)?|timestamp)\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if (not (defined $self->datetime_undef_if_invalid && $self->datetime_undef_if_invalid == 0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->datetime_undef_if_invalid and $self->datetime_undef_if_invalid == 0
MC/DC0%0/2
defined $self->datetime_undef_if_invalid and $self->datetime_undef_if_invalid == 0
defined $self->datetime_undef_if_invalid
$self->datetime_undef_if_invalid == 0
Truth table0%0/3
A and B
A= defined $self->datetime_undef_if_invalidB= $self->datetime_undef_if_invalid == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $info->{datetime_undef_if_invalid} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | ▶ | elsif ($data_type =~ /^(?:enum|set)\z/ && $has_information_schema | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$data_type =~ /^(?:enum|set)\z/ and $has_information_schema and $column_type =~ /^(?:enum|set)\(/
$data_type =~ /^(?:enum|set)\z/ and $has_information_schema
MC/DC0%0/3
$data_type =~ /^(?:enum|set)\z/ and $has_information_schema and $column_type =~ /^(?:enum|set)\(/
$data_type =~ /^(?:enum|set)\z/
$has_information_schema
$column_type =~ /^(?:enum|set)\(/
Truth table0%0/4
A and B and C
A= $data_type =~ /^(?:enum|set)\z/B= $has_information_schemaC= $column_type =~ /^(?:enum|set)\(/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | && $column_type =~ /^(?:enum|set)\(/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | delete $info->{extra}{list}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | while ($column_type =~ /'((?:[^']* (?:''|\\')* [^']*)* [^\\']?)',?/xg) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $el = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $el =~ s/''/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | push @{ $info->{extra}{list} }, $el; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # Sometimes apparently there's a bug where default_value gets set to '' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # for things that don't actually have or support that default (like ints.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if (exists $info->{default_value} && $info->{default_value} eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $info->{"default_value"} and $info->{"default_value"} eq ""
MC/DC0%0/2
exists $info->{"default_value"} and $info->{"default_value"} eq ""
exists $info->{"default_value"}
$info->{"default_value"} eq ""
Truth table0%0/3
A and B
A= exists $info->{"default_value"}B= $info->{"default_value"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ($has_information_schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if (not defined $default) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | delete $info->{default_value}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | else { # just check if it's a char/text type, otherwise remove | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | delete $info->{default_value} unless $data_type =~ /char|text/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | sub _extra_column_info { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extra_column_info: not called CC=7 SCAR=37.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my ($self, $table, $col, $info, $dbi_info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my %extra_info; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ($dbi_info->{mysql_is_auto_increment}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $extra_info{is_auto_increment} = 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ($dbi_info->{mysql_type_name} =~ /\bunsigned\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $extra_info{extra}{unsigned} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ($dbi_info->{mysql_values}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $extra_info{extra}{list} = $dbi_info->{mysql_values}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if ((not blessed $dbi_info) # isa $sth | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not builtin::blessed($dbi_info) and lc $dbi_info->{"COLUMN_DEF"} eq "current_timestamp" and lc $dbi_info->{"mysql_type_name"} eq "timestamp"
not builtin::blessed($dbi_info) and lc $dbi_info->{"COLUMN_DEF"} eq "current_timestamp"
MC/DC0%0/3
not builtin::blessed($dbi_info) and lc $dbi_info->{"COLUMN_DEF"} eq "current_timestamp" and lc $dbi_info->{"mysql_type_name"} eq "timestamp"
not builtin::blessed($dbi_info)
lc $dbi_info->{"COLUMN_DEF"} eq "current_timestamp"
lc $dbi_info->{"mysql_type_name"} eq "timestamp"
Truth table0%0/4
not(A) and B and C
A= not builtin::blessed($dbi_info)B= lc $dbi_info->{"COLUMN_DEF"} eq "current_timestamp"C= lc $dbi_info->{"mysql_type_name"} eq "timestamp"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | && lc($dbi_info->{COLUMN_DEF}) eq 'current_timestamp' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | && lc($dbi_info->{mysql_type_name}) eq 'timestamp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $current_timestamp = 'current_timestamp'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $extra_info{default_value} = \$current_timestamp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return \%extra_info; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | sub _dbh_column_info { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_column_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | local $SIG{__WARN__} = sigwarn_silencer( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | qr/^column_info: unrecognized column type/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub _table_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table_comment: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my ( $self, $table ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $comment = $self->next::method($table); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if (not $comment) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | ($comment) = try { $self->schema->storage->dbh->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | qq{SELECT table_comment | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | FROM information_schema.tables | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | WHERE table_schema = schema() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | AND table_name = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | }, undef, $table->name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # InnoDB likes to auto-append crap. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if (not $comment) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # Do nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | elsif ($comment =~ /^InnoDB free:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $comment = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $comment =~ s/; InnoDB.*//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | return $comment; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | sub _column_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_column_comment: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my ( $self, $table, $column_number, $column_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $comment = $self->next::method($table, $column_number, $column_name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if (not $comment) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | ($comment) = try { $self->schema->storage->dbh->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | qq{SELECT column_comment | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | FROM information_schema.columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | WHERE table_schema = schema() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | AND table_name = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | AND lower(column_name) = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | }, undef, $table->name, lc($column_name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return $comment; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | sub _view_definition { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_view_definition: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my ($self, $view) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | return scalar $self->schema->storage->dbh->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | q{SELECT view_definition | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | FROM information_schema.views | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | WHERE table_schema = schema() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | AND table_name = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | }, undef, $view->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | L<DBIx::Class::Schema::Loader::DBI> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | See L<DBIx::Class::Schema::Loader/AUTHORS>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # vim:et sw=4 sts=4 tw=0: | ||||||||||||||||||||||||||||||||||||||||||||||||||