| 1 | package DBIO::MySQL::Test::Conformance; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Answers the shared conformance case table for the MySQL and MariaDB driver | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use base 'DBIO::Test::Conformance'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use DBI (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use DBIO::MySQL::Introspect (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use DBIO::MySQL::Deploy (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use DBIO::MySQL::DDL (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use DBIO::MySQL::Identifier (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | my $SEQ = 0; | |||||||||||||||||||||||||||
| 20 | # schema class => the name of its case's database | ||||||||||||||||||||||||||||
| 21 | 5 | my %NAMESPACE; | |||||||||||||||||||||||||||
| 22 | # schema class => 1 when this run created the database | ||||||||||||||||||||||||||||
| 23 | my %CREATED; | ||||||||||||||||||||||||||||
| 24 | # schema class => { 'database.table' => 1 }: the tables this run made in other databases | ||||||||||||||||||||||||||||
| 25 | 5 | my %QUALIFIED; | |||||||||||||||||||||||||||
| 26 | 5 | my $SERVER; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _admin_connect { | ||||||||||||||||||||||||||
|
Subroutine
_admin_connect: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($dsn) = @_; | |||||||||||||||||||||||||||
| 30 | return DBI->connect($dsn // $ENV{DBIO_TEST_MYSQL_DSN}, | ||||||||||||||||||||||||||||
| 31 | $ENV{DBIO_TEST_MYSQL_USER}, $ENV{DBIO_TEST_MYSQL_PASS}, { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | AutoCommit => 1, RaiseError => 1, PrintError => 0, PrintWarn => 0, | ||||||||||||||||||||||||||
|
Condition0%0/3
$dsn // $ENV{"DBIO_TEST_MYSQL_DSN"}
MC/DC0%0/2
$dsn // $ENV{"DBIO_TEST_MYSQL_DSN"}
$dsn
$ENV{"DBIO_TEST_MYSQL_DSN"}
Truth table0%0/3
A // B
A= $dsnB= $ENV{"DBIO_TEST_MYSQL_DSN"}
| |||||||||||||||||||||||||||||
| 33 | }); | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # The DSN of the case: the one of the environment, naming the database of | ||||||||||||||||||||||||||||
| 37 | # the case. | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub _case_dsn { | ||||||||||||||||||||||||||
|
Subroutine
_case_dsn: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($name) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | my $dsn = $ENV{DBIO_TEST_MYSQL_DSN}; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | $dsn =~ s/\b(?:database|dbname)=[^;]*/database=$name/i | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | or $dsn .= ";database=$name"; | ||||||||||||||||||||||||||||
| 43 | 0 | return $dsn; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | sub conformance_live_available { | ||||||||||||||||||||||||||
|
Subroutine
conformance_live_available: called CC=4 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | my ($driver) = ($ENV{DBIO_TEST_MYSQL_DSN} // '') =~ /\Adbi:(\w+):/i | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{"DBIO_TEST_MYSQL_DSN"} // ""
MC/DC0%0/1
$ENV{"DBIO_TEST_MYSQL_DSN"} // ""
$ENV{"DBIO_TEST_MYSQL_DSN"}
Truth table50%1/2
A
A= $ENV{"DBIO_TEST_MYSQL_DSN"}
| |||||||||||||||||||||||||||||
| 49 | or return 0; | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return eval { require "DBD/$driver.pm"; 1 } ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub conformance_connect { | ||||||||||||||||||||||||||
|
Subroutine
conformance_connect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($class, $schema_class) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | my $name = sprintf 'dbio_cf_%d_%d', $$, ++$SEQ; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $admin = _admin_connect(); | |||||||||||||||||||||||||||
| 59 | 0 | $admin->do('CREATE DATABASE ' . DBIO::MySQL::Identifier::quote_ident($name)); | |||||||||||||||||||||||||||
| 60 | 0 | $admin->disconnect; | |||||||||||||||||||||||||||
| 61 | 0 | $NAMESPACE{$schema_class} = $name; | |||||||||||||||||||||||||||
| 62 | 0 | $CREATED{$schema_class} = 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | $schema_class->load_components('MySQL'); | |||||||||||||||||||||||||||
| 65 | 0 | my $dsn = _case_dsn($name); | |||||||||||||||||||||||||||
| 66 | 0 | my %attrs = ( | |||||||||||||||||||||||||||
| 67 | AutoCommit => 1, RaiseError => 1, PrintError => 0, PrintWarn => 0, | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $attrs{mysql_enable_utf8mb4} = 1 if $dsn =~ /\Adbi:mysql:/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | %attrs = (%attrs, $class->conformance_connect_attributes); | |||||||||||||||||||||||||||
| 71 | return $schema_class->connect($dsn, | ||||||||||||||||||||||||||||
| 72 | 0 | @ENV{qw(DBIO_TEST_MYSQL_USER DBIO_TEST_MYSQL_PASS)}, \%attrs); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub conformance_connect_attributes { return } | ||||||||||||||||||||||||||
|
Subroutine
conformance_connect_attributes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _namespace_of { | ||||||||||||||||||||||||||
|
Subroutine
_namespace_of: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 79 | 0 | my ($class, $schema) = @_; | |||||||||||||||||||||||||||
| 80 | 0 | my $name = $NAMESPACE{ ref $schema }; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | DBIO::Exception->throw('conformance: this schema was not connected through ' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | . 'conformance_connect') unless defined $name; | ||||||||||||||||||||||||||||
| 83 | 0 | return $name; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub conformance_namespace { | ||||||||||||||||||||||||||
|
Subroutine
conformance_namespace: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my ($class, $schema, $case) = @_; | |||||||||||||||||||||||||||
| 89 | 0 | my $name = $class->_namespace_of($schema); | |||||||||||||||||||||||||||
| 90 | 0 | my ($n) = $schema->storage->dbh->selectrow_array( | |||||||||||||||||||||||||||
| 91 | 'SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ?', | ||||||||||||||||||||||||||||
| 92 | undef, $name); | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | DBIO::Exception->throw("conformance: the database '$name' is not empty") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | if $n; | ||||||||||||||||||||||||||||
| 95 | 0 | return { name => $name }; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub conformance_install { | ||||||||||||||||||||||||||
|
Subroutine
conformance_install: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my ($class, $schema, $case) = @_; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | my @qualified = DBIO::MySQL::DDL->qualified_tables($schema); | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (@qualified) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||
| 105 | 0 | for my $pair (@qualified) { | |||||||||||||||||||||||||||
| 106 | 0 | my ($table, $database) = @$pair; | |||||||||||||||||||||||||||
| 107 | 0 | my (undef, $short) = DBIO::MySQL::Identifier::split_table_name($table); | |||||||||||||||||||||||||||
| 108 | 0 | my ($there) = $dbh->selectrow_array( | |||||||||||||||||||||||||||
| 109 | 'SELECT COUNT(*) FROM information_schema.tables ' | ||||||||||||||||||||||||||||
| 110 | . 'WHERE table_schema = ? AND table_name = ?', undef, $database, $short); | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | DBIO::Exception->throw("conformance: the table '$table' is on the server " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | . 'already; it is not the run\'s to use or drop') if $there; | ||||||||||||||||||||||||||||
| 113 | 0 | $QUALIFIED{ ref $schema }{$table} = 1; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | $schema->deploy; | |||||||||||||||||||||||||||
| 119 | 0 | return; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub conformance_cleanup { | ||||||||||||||||||||||||||
|
Subroutine
conformance_cleanup: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 0 | my ($class, $schema, $case, $namespace) = @_; | |||||||||||||||||||||||||||
| 125 | 0 | my $created = delete $CREATED{ ref $schema }; | |||||||||||||||||||||||||||
| 126 | 0 | my $name = delete $NAMESPACE{ ref $schema }; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $qualified = delete $QUALIFIED{ ref $schema } || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $QUALIFIED{ref $schema} || {}
MC/DC0%0/1
delete $QUALIFIED{ref $schema} || {}
delete $QUALIFIED{ref $schema}
Truth table0%0/2
A
A= delete $QUALIFIED{ref $schema}
| |||||||||||||||||||||||||||||
| 128 | 0 | eval { $schema->storage->disconnect }; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if (my @tables = sort keys %$qualified) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||
| 132 | 0 | $dbh->do('DROP TABLE IF EXISTS ' . DBIO::MySQL::Identifier::quote_table($_)) for @tables; | |||||||||||||||||||||||||||
| 133 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($created && defined $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$created and defined $name
MC/DC0%0/2
$created and defined $name
$created
defined $name
Truth table0%0/3
A and B
A= $createdB= defined $name
| |||||||||||||||||||||||||||||
| 137 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||
| 138 | 0 | $dbh->do('DROP DATABASE IF EXISTS ' . DBIO::MySQL::Identifier::quote_ident($name)); | |||||||||||||||||||||||||||
| 139 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 0 | return; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub conformance_diff_is_empty { | ||||||||||||||||||||||||||
|
Subroutine
conformance_diff_is_empty: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 0 | my ($class, $schema, $case) = @_; | |||||||||||||||||||||||||||
| 147 | 0 | my $diff = DBIO::MySQL::Deploy->new(schema => $schema)->diff; | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | return $diff->has_changes ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub conformance_upgrade { | ||||||||||||||||||||||||||
|
Subroutine
conformance_upgrade: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 0 | my ($class, $schema, $to_class, $case) = @_; | |||||||||||||||||||||||||||
| 154 | 0 | my $name = $class->_namespace_of($schema); | |||||||||||||||||||||||||||
| 155 | 0 | my $to = $class->_connect_target($to_class, $name); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # A refusal ends the case with the installed schema: the database stays | ||||||||||||||||||||||||||||
| 158 | # its, and its cleanup drops it. | ||||||||||||||||||||||||||||
| 159 | 0 | my $ok = eval { DBIO::MySQL::Deploy->new(schema => $to)->upgrade(allow_destructive => 1); 1 }; | |||||||||||||||||||||||||||
| 160 | 0 | my $err = $@; | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | eval { $to->storage->disconnect }; | |||||||||||||||||||||||||||
| 163 | 0 | die $err; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | $class->_hand_over_namespace($schema, $to_class, $name); | |||||||||||||||||||||||||||
| 167 | 0 | return $to; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub conformance_deploy { | ||||||||||||||||||||||||||
|
Subroutine
conformance_deploy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 0 | my ($class, $schema, $to_class, $case) = @_; | |||||||||||||||||||||||||||
| 173 | 0 | my $name = $class->_namespace_of($schema); | |||||||||||||||||||||||||||
| 174 | 0 | my $to = $class->_connect_target($to_class, $name); | |||||||||||||||||||||||||||
| 175 | 0 | $class->_hand_over_namespace($schema, $to_class, $name); | |||||||||||||||||||||||||||
| 176 | 0 | return DBIO::MySQL::Deploy->new(schema => $to); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | # The target class, connected to the database of the installed schema. | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub _connect_target { | ||||||||||||||||||||||||||
|
Subroutine
_connect_target: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 181 | 0 | my ($class, $to_class, $name) = @_; | |||||||||||||||||||||||||||
| 182 | 0 | $to_class->load_components('MySQL'); | |||||||||||||||||||||||||||
| 183 | 0 | my $dsn = _case_dsn($name); | |||||||||||||||||||||||||||
| 184 | 0 | my %attrs = ( | |||||||||||||||||||||||||||
| 185 | AutoCommit => 1, RaiseError => 1, PrintError => 0, PrintWarn => 0, | ||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $attrs{mysql_enable_utf8mb4} = 1 if $dsn =~ /\Adbi:mysql:/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | return $to_class->connect($dsn, | ||||||||||||||||||||||||||||
| 189 | 0 | @ENV{qw(DBIO_TEST_MYSQL_USER DBIO_TEST_MYSQL_PASS)}, \%attrs); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # The database now belongs to the target's class: the runner cleans up | ||||||||||||||||||||||||||||
| 193 | # through the schema it gets back, and closes $schema itself afterwards. | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub _hand_over_namespace { | ||||||||||||||||||||||||||
|
Subroutine
_hand_over_namespace: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 195 | 0 | my ($class, $schema, $to_class, $name) = @_; | |||||||||||||||||||||||||||
| 196 | 0 | $NAMESPACE{$to_class} = $name; | |||||||||||||||||||||||||||
| 197 | 0 | $CREATED{$to_class} = delete $CREATED{ ref $schema }; | |||||||||||||||||||||||||||
| 198 | 0 | delete $NAMESPACE{ ref $schema }; | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | $QUALIFIED{$to_class} = delete $QUALIFIED{ ref $schema } if $QUALIFIED{ ref $schema }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | return; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 4 | ▶ | sub conformance_answered_through { { DDL => 2, Diff => 4, Bind => 1 } } | ||||||||||||||||||||||||||
|
Subroutine
conformance_answered_through: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub conformance_server_is_mariadb { | ||||||||||||||||||||||||||
|
Subroutine
conformance_server_is_mariadb: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return $SERVER if defined $SERVER; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||
| 210 | 0 | my ($version) = $dbh->selectrow_array('SELECT VERSION()'); | |||||||||||||||||||||||||||
| 211 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||
| 212 | 0 | ▶ | return $SERVER = ($version // '') =~ /mariadb/i ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$version // ""
MC/DC0%0/1
$version // ""
$version
Truth table0%0/2
A
A= $version
| |||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 3 | ▶ | sub conformance_refusals { | ||||||||||||||||||||||||||
|
Subroutine
conformance_refusals: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 217 | 3 | my ($class) = @_; | |||||||||||||||||||||||||||
| 218 | 3 | my $refusals = { | |||||||||||||||||||||||||||
| 219 | 'diff-column-added-not-null-populated' => { | ||||||||||||||||||||||||||||
| 220 | kind => 'server', | ||||||||||||||||||||||||||||
| 221 | reason => qr/NOT NULL without a default, and table base holds rows/, | ||||||||||||||||||||||||||||
| 222 | }, | ||||||||||||||||||||||||||||
| 223 | 'diff-not-null-over-nulls' => { | ||||||||||||||||||||||||||||
| 224 | kind => 'server', | ||||||||||||||||||||||||||||
| 225 | reason => qr/holds rows where it is NULL/, | ||||||||||||||||||||||||||||
| 226 | }, | ||||||||||||||||||||||||||||
| 227 | }; | ||||||||||||||||||||||||||||
| 228 | 3 | ▶ | $refusals->{'ddl-qualified-source-name'} = { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class->conformance_live_available and not $class->_database_exists("other")
MC/DC0%0/2
$class->conformance_live_available and not $class->_database_exists("other")
$class->conformance_live_available
not $class->_database_exists("other")
Truth table33%1/3
A and not(B)
A= $class->conformance_live_availableB= not $class->_database_exists("other")
| |||||||||||||||||||||||||||||
| 229 | kind => 'server', | ||||||||||||||||||||||||||||
| 230 | reason => qr/the database other does not exist/, | ||||||||||||||||||||||||||||
| 231 | } if $class->conformance_live_available && !$class->_database_exists('other'); | ||||||||||||||||||||||||||||
| 232 | 3 | return $refusals; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # Whether the server has a database of exactly that name; asked once per name | ||||||||||||||||||||||||||||
| 236 | # and process, and read only. | ||||||||||||||||||||||||||||
| 237 | 5 | my %DATABASE_EXISTS; | |||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub _database_exists { | ||||||||||||||||||||||||||
|
Subroutine
_database_exists: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 239 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | return $DATABASE_EXISTS{$name} //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$DATABASE_EXISTS{$name} //= do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
MC/DC0%0/2
$DATABASE_EXISTS{$name} //= do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
$DATABASE_EXISTS{$name}
do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
Truth table0%0/3
A //= B
A= $DATABASE_EXISTS{$name}B= do {
my $dbh = _admin_connect();
my($found) = $dbh->selectrow_array("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = ?", undef, $name);
$dbh->disconnect;
$found ? 1 : 0
}
| |||||||||||||||||||||||||||||
| 241 | 0 | my $dbh = _admin_connect(); | |||||||||||||||||||||||||||
| 242 | 0 | my ($found) = $dbh->selectrow_array( | |||||||||||||||||||||||||||
| 243 | 'SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = ?', | ||||||||||||||||||||||||||||
| 244 | undef, $name); | ||||||||||||||||||||||||||||
| 245 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||
| 246 | 0 | ▶ | $found ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | }; | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub conformance_fact { | ||||||||||||||||||||||||||
|
Subroutine
conformance_fact: not called CC=24 SCAR=64.0
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | 0 | my ($class, $schema, $name, $args) = @_; | |||||||||||||||||||||||||||
| 253 | 0 | my $dbh = $schema->storage->dbh; | |||||||||||||||||||||||||||
| 254 | 0 | my $table = $args->{table}; | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if ($name eq 'table_in_namespace') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | my ($n) = $dbh->selectrow_array( | ||||||||||||||||||||||||||||
| 258 | 'SELECT COUNT(*) FROM information_schema.tables ' | ||||||||||||||||||||||||||||
| 259 | . 'WHERE table_schema = ? AND table_name = ?', | ||||||||||||||||||||||||||||
| 260 | 0 | undef, $args->{namespace}, $args->{unqualified}); | |||||||||||||||||||||||||||
| 261 | 0 | ▶ | return $n ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | my $model = DBIO::MySQL::Introspect->new(dbh => $dbh)->model; | |||||||||||||||||||||||||||
| 265 | 0 | my $entry = $model->{tables}{$table}; | |||||||||||||||||||||||||||
| 266 | 0 | ▶ | my @cols = @{ $args->{columns} || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'columns'} || []
MC/DC0%0/1
$args->{'columns'} || []
$args->{'columns'}
Truth table0%0/2
A
A= $args->{'columns'}
| |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | my $same = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 268 | 0 | my ($got) = @_; | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | return 0 unless @$got == @cols; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | return (join("\0", map { $_ // '' } @$got) eq join("\0", @cols)) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$_ // ""
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||||||||
| 271 | 0 | }; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if ($name eq 'object_kind') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return $entry ? $entry->{kind} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ($name eq 'table_name') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | return $entry ? $entry->{table_name} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | ▶ | my $columns = $model->{columns}{$table} || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$model->{'columns'}{$table} || []
MC/DC0%0/1
$model->{'columns'}{$table} || []
$model->{'columns'}{$table}
Truth table0%0/2
A
A= $model->{'columns'}{$table}
| |||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ($name eq 'column_names') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 0 | return [ map { $_->{column_name} } @$columns ]; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if ($name eq 'column_size') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns; | |||||||||||||||||||||||||||
| 286 | 0 | ▶ | return $col ? $col->{size} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ($name eq 'column_auto_increment') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | my ($col) = grep { $_->{column_name} eq $args->{column} } @$columns; | |||||||||||||||||||||||||||
| 290 | 0 | ▶ | return $col && $col->{is_auto_increment} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$col and $col->{"is_auto_increment"}
MC/DC0%0/2
$col and $col->{"is_auto_increment"}
$col
$col->{"is_auto_increment"}
Truth table0%0/3
A and B
A= $colB= $col->{"is_auto_increment"}
| |||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $indexes = $model->{indexes}{$table} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$model->{'indexes'}{$table} || {}
MC/DC0%0/1
$model->{'indexes'}{$table} || {}
$model->{'indexes'}{$table}
Truth table0%0/2
A
A= $model->{'indexes'}{$table}
| |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($name eq 'primary_key_columns') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | return [ map { $_->{column_name} } | |||||||||||||||||||||||||||
| 296 | 0 | sort { $a->{pk_position} <=> $b->{pk_position} } | |||||||||||||||||||||||||||
| 297 | 0 | grep { $_->{is_pk} } @$columns ]; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ($name eq 'unique_exists') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | return (grep { $_->{origin} eq 'u' and $same->($_->{columns}) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->{'origin'} eq 'u' && &$same($_->{'columns'})
MC/DC0%0/2
$_->{'origin'} eq 'u' && &$same($_->{'columns'})
$_->{'origin'} eq 'u'
&$same($_->{'columns'})
Truth table0%0/3
A && B
A= $_->{'origin'} eq 'u'B= &$same($_->{'columns'})
| |||||||||||||||||||||||||||||
| 301 | values %$indexes) ? 1 : 0; | ||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($name eq 'foreign_key_count') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 0 | ▶ | return scalar @{ $model->{foreign_keys}{$table} || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$model->{'foreign_keys'}{$table} || []
MC/DC0%0/1
$model->{'foreign_keys'}{$table} || []
$model->{'foreign_keys'}{$table}
Truth table0%0/2
A
A= $model->{'foreign_keys'}{$table}
| |||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($name eq 'index_count') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | return scalar grep { $_->{origin} ne 'pk' and $same->($_->{columns}) } | ||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'origin'} ne 'pk' && &$same($_->{'columns'})
MC/DC0%0/2
$_->{'origin'} ne 'pk' && &$same($_->{'columns'})
$_->{'origin'} ne 'pk'
&$same($_->{'columns'})
Truth table0%0/3
A && B
A= $_->{'origin'} ne 'pk'B= &$same($_->{'columns'})
| |||||||||||||||||||||||||||||
| 308 | values %$indexes; | ||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 0 | DBIO::Exception->throw("unknown conformance fact '$name'"); | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 5 | 1; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | __END__ | ||||||||||||||||||||||||||||