| 1 | # TODO: Find out why DBI croaks under PerlSvc when DBD::Wire10 and Net::Wire10 | ||||||||||||||||||||||||||||||||
| 2 | # files are in UTF-8 (with BOM), this prevents using Unicode for the POD docs. | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | # TODO: Put in a place where people expect to find this driver, maybe alias | ||||||||||||||||||||||||||||||||
| 5 | # under package names matching the supported database systems? | ||||||||||||||||||||||||||||||||
| 6 | # (DBD::MySQL::Wire10, DBD::Sphinx::Wire10, DBD::Drizzle::Wire10 etc) | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | package DBD::Wire10; | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use DBI; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use vars qw($VERSION $err $errstr $state $drh); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 2 | $VERSION = '1.08'; | |||||||||||||||||||||||||||||||
| 16 | 2 | $err = 0; | |||||||||||||||||||||||||||||||
| 17 | 2 | $errstr = ''; | |||||||||||||||||||||||||||||||
| 18 | 2 | $state = undef; | |||||||||||||||||||||||||||||||
| 19 | 2 | $drh = undef; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 2 | our $methods_already_installed = 0; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub driver { | ||||||||||||||||||||||||||||||
|
Subroutine
driver: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $drh if $drh; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 27 | 0 | my $attr = shift; | |||||||||||||||||||||||||||||||
| 28 | 0 | $class .= '::dr'; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | # TODO: core->ping() + core->connect() useful as a generic mechanism | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | unless ($methods_already_installed++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 0 | eval { | |||||||||||||||||||||||||||||||
| 33 | 0 | my $method = "DBI::db::reconnect"; | |||||||||||||||||||||||||||||||
| 34 | 0 | my $file = "__FILENAME__"; | |||||||||||||||||||||||||||||||
| 35 | 0 | my $info = {}; | |||||||||||||||||||||||||||||||
| 36 | 0 | DBI->_install_method($method, $file, $info); | |||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | warn "Failed to register reconnect method: $@" if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 0 | $drh = DBI::_new_drh($class, { | |||||||||||||||||||||||||||||||
| 42 | Name => 'Wire10', | ||||||||||||||||||||||||||||||||
| 43 | Version => $VERSION, | ||||||||||||||||||||||||||||||||
| 44 | }, {}); | ||||||||||||||||||||||||||||||||
| 45 | 0 | return $drh; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub CLONE { | ||||||||||||||||||||||||||||||
|
Subroutine
CLONE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 49 | 0 | undef $drh; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | # TODO: Is there a shrinkwrapped function to do this | ||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub _parse_dsn { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_dsn: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||
| 54 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 55 | 0 | my ($dsn, $args) = @_; | |||||||||||||||||||||||||||||||
| 56 | 0 | my ($hash, $var, $val); | |||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return undef if ! defined $dsn; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | while (length $dsn) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($dsn =~ /([^:;]*)[:;](.*)/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 0 | $val = $1; | |||||||||||||||||||||||||||||||
| 62 | 0 | $dsn = $2; | |||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||
| 64 | 0 | $val = $dsn; | |||||||||||||||||||||||||||||||
| 65 | 0 | $dsn = ''; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($val =~ /([^=]*)=(.*)/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 0 | $var = $1; | |||||||||||||||||||||||||||||||
| 69 | 0 | $val = $2; | |||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($var eq 'hostname' || $var eq 'host') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$var eq "hostname" or $var eq "host"
MC/DC0%0/2
$var eq "hostname" or $var eq "host"
$var eq "hostname"
$var eq "host"
Truth table0%0/3
A or B
A= $var eq "hostname"B= $var eq "host"
| |||||||||||||||||||||||||||||||||
| 71 | 0 | $hash->{host} = $val; | |||||||||||||||||||||||||||||||
| 72 | ▶ | } elsif ($var eq 'db' || $var eq 'dbname') { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$var eq "db" or $var eq "dbname"
MC/DC0%0/2
$var eq "db" or $var eq "dbname"
$var eq "db"
$var eq "dbname"
Truth table0%0/3
A or B
A= $var eq "db"B= $var eq "dbname"
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $hash->{database} = $val; | |||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||
| 75 | 0 | $hash->{$var} = $val; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||||
| 78 | 0 | for $var (@$args) { | |||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (! defined($hash->{$var})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 0 | $hash->{$var} = $val; | |||||||||||||||||||||||||||||||
| 81 | 0 | last; | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | 0 | return $hash; | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub _parse_dsn_host { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_dsn_host: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 90 | 0 | my ($class, $dsn) = @_; | |||||||||||||||||||||||||||||||
| 91 | 0 | my $hash = $class->_parse_dsn($dsn, ['host', 'port']); | |||||||||||||||||||||||||||||||
| 92 | 0 | return ($hash->{host}, $hash->{port}); | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | package DBD::Wire10::dr; | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | use Net::Wire10; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | # Note: rather undocumented, for now blindly hoping that 0 means auto-detect. | ||||||||||||||||||||||||||||||||
| 104 | 2 | $DBD::Wire10::dr::imp_data_size = 0; | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 107 | 0 | my $drh = shift; | |||||||||||||||||||||||||||||||
| 108 | 0 | my ($dsn, $user, $password, $attrhash) = @_; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | my $data_source_info = DBD::Wire10->_parse_dsn( | |||||||||||||||||||||||||||||||
| 111 | $dsn, ['database', 'host', 'port'], | ||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $user ||= ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$user ||= ""
MC/DC0%0/1
$user ||= ""
$user
Truth table0%0/2
A
A= $user
| |||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $password ||= ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$password ||= ""
MC/DC0%0/1
$password ||= ""
$password
Truth table0%0/2
A
A= $password
| |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 0 | my $dbh = DBI::_new_dbh($drh, { Name => $dsn }); | |||||||||||||||||||||||||||||||
| 117 | 0 | eval { | |||||||||||||||||||||||||||||||
| 118 | # See note in take_imp_data(). | ||||||||||||||||||||||||||||||||
| 119 | 0 | my $wire = delete $attrhash->{dbi_imp_data}; | |||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | unless (defined $wire) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | $wire = Net::Wire10->new( | ||||||||||||||||||||||||||||||||
| 122 | host => $data_source_info->{host}, | ||||||||||||||||||||||||||||||||
| 123 | port => $data_source_info->{port}, | ||||||||||||||||||||||||||||||||
| 124 | database => $data_source_info->{database}, | ||||||||||||||||||||||||||||||||
| 125 | user => $user, | ||||||||||||||||||||||||||||||||
| 126 | password => $password, | ||||||||||||||||||||||||||||||||
| 127 | debug => $attrhash->{wire10_debug} || undef, | ||||||||||||||||||||||||||||||||
| 128 | connect_timeout => $attrhash->{wire10_connect_timeout} || undef, | ||||||||||||||||||||||||||||||||
| 129 | query_timeout => $attrhash->{wire10_query_timeout} || undef, | ||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$attrhash->{'wire10_debug'} || undef
$attrhash->{'wire10_connect_timeout'} || undef
$attrhash->{'wire10_query_timeout'} || undef
MC/DC0%0/1
$attrhash->{'wire10_debug'} || undef
$attrhash->{'wire10_debug'}
MC/DC0%0/1
$attrhash->{'wire10_connect_timeout'} || undef
$attrhash->{'wire10_connect_timeout'}
MC/DC0%0/1
$attrhash->{'wire10_query_timeout'} || undef
$attrhash->{'wire10_query_timeout'}
Truth table0%0/2
A
A= $attrhash->{'wire10_debug'}
Truth table0%0/2
A
A= $attrhash->{'wire10_connect_timeout'}
Truth table0%0/2
A
A= $attrhash->{'wire10_query_timeout'}
| |||||||||||||||||||||||||||||||||
| 131 | 0 | $wire->connect; | |||||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||||||
| 133 | 0 | $dbh->STORE('wire10_driver_dbh', $wire); | |||||||||||||||||||||||||||||||
| 134 | 0 | $dbh->STORE('wire10_thread_id', $wire->{server_thread_id}); | |||||||||||||||||||||||||||||||
| 135 | 0 | $dbh->STORE('wire10_server_version', $wire->{server_version}); | |||||||||||||||||||||||||||||||
| 136 | }; | ||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | 0 | $dbh->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 139 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | 0 | $dbh->STORE('Active', 1); | |||||||||||||||||||||||||||||||
| 142 | 0 | return $dbh; | |||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub data_sources { | ||||||||||||||||||||||||||||||
|
Subroutine
data_sources: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 146 | 0 | return ("DBI:Wire10:"); | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | package DBD::Wire10::db; | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 2 | $DBD::Wire10::db::imp_data_size = 0; | |||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub quote { | ||||||||||||||||||||||||||||||
|
Subroutine
quote: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 159 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 160 | 0 | my ($statement, $type) = @_; | |||||||||||||||||||||||||||||||
| 161 | 0 | return Net::Wire10::Util::quote($statement); | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub quote_identifier { | ||||||||||||||||||||||||||||||
|
Subroutine
quote_identifier: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 165 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 166 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||
| 167 | 0 | return Net::Wire10::Util::quote_identifier($name); | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub prepare { | ||||||||||||||||||||||||||||||
|
Subroutine
prepare: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 171 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 172 | 0 | my ($statement, @attribs) = @_; | |||||||||||||||||||||||||||||||
| 173 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 0 | my $sth; | |||||||||||||||||||||||||||||||
| 176 | 0 | eval { | |||||||||||||||||||||||||||||||
| 177 | 0 | $sth = DBI::_new_sth($dbh, {Statement => $statement}); | |||||||||||||||||||||||||||||||
| 178 | 0 | DBD::Wire10::st::_constructor($sth, $wire, $statement); | |||||||||||||||||||||||||||||||
| 179 | }; | ||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | 0 | $dbh->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 182 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | 0 | return $sth; | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||
| 188 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 189 | 0 | my ($key, $value) = @_; | |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ($key =~ /^AutoCommit$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 192 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 193 | 0 | eval { | |||||||||||||||||||||||||||||||
| 194 | 0 | $wire->query("SET AUTOCOMMIT=".$value); | |||||||||||||||||||||||||||||||
| 195 | }; | ||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | die $@ unless $wire->is_connected; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ($dbh->FETCH('Warn')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | 0 | warn "Server does not allow setting AUTOCOMMIT: $@"; | |||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | # Can't store as AutoCommit via SUPER::STORE, not sure why. | ||||||||||||||||||||||||||||||||
| 203 | 0 | $dbh->STORE('wire10_autocommit', $value); | |||||||||||||||||||||||||||||||
| 204 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($key =~ /^(?:wire10_connect_timeout)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 208 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 209 | 0 | $wire->{connect_timeout} = $value; | |||||||||||||||||||||||||||||||
| 210 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ($key =~ /^(?:wire10_query_timeout)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 214 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 215 | 0 | $wire->{query_timeout} = $value; | |||||||||||||||||||||||||||||||
| 216 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ($key =~ /^(?:wire10_debug)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 221 | 0 | $wire->{debug} = $value; | |||||||||||||||||||||||||||||||
| 222 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ($key =~ /^(?:wire10_.*)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 226 | 0 | $dbh->{$key} = $value; | |||||||||||||||||||||||||||||||
| 227 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | 0 | return $dbh->SUPER::STORE($key, $value); | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 234 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 235 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ($key =~ /^(?:wire10_connect_timeout)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 238 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 239 | 0 | return $wire->{connect_timeout}; | |||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ($key =~ /^(?:wire10_query_timeout)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 242 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 243 | 0 | return $wire->{query_timeout}; | |||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if ($key =~ /^(?:wire10_debug)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 246 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 247 | 0 | return $wire->{debug}; | |||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ($key =~ /^AutoCommit$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 251 | # See comment in STORE. | ||||||||||||||||||||||||||||||||
| 252 | 0 | return $dbh->FETCH('wire10_autocommit'); | |||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | return $dbh->{$key} if $key =~ /^(?:wire10_.*)$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 256 | 0 | return $dbh->SUPER::FETCH($key); | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub commit { | ||||||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 260 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($dbh->FETCH('AutoCommit')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ($dbh->FETCH('Warn')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | 0 | warn 'Commit ineffective while AutoCommit is on'; | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 269 | 0 | $wire->query("COMMIT"); | |||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | sub rollback { | ||||||||||||||||||||||||||||||
|
Subroutine
rollback: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 275 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if ($dbh->FETCH('AutoCommit')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ($dbh->FETCH('Warn')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 279 | 0 | warn 'Rollback ineffective while AutoCommit is on'; | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 284 | 0 | $wire->query("ROLLBACK"); | |||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub ping { | ||||||||||||||||||||||||||||||
|
Subroutine
ping: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 290 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 291 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | 0 | eval { | |||||||||||||||||||||||||||||||
| 294 | 0 | $wire->ping; | |||||||||||||||||||||||||||||||
| 295 | }; | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | 0 | my $error = $wire->get_error_info; | |||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | $dbh->DBI::set_err($error->get_error_code || -1, $error->get_error_message, $error->get_error_state); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$error->get_error_code || -1
MC/DC0%0/1
$error->get_error_code || -1
$error->get_error_code
Truth table0%0/2
A
A= $error->get_error_code
| |||||||||||||||||||||||||||||||||
| 300 | } elsif ($@) { | ||||||||||||||||||||||||||||||||
| 301 | 0 | $dbh->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | 0 | return $wire->is_connected; | |||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub reconnect { | ||||||||||||||||||||||||||||||
|
Subroutine
reconnect: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 308 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 309 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ($wire->is_connected) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | 0 | eval { | |||||||||||||||||||||||||||||||
| 313 | 0 | $wire->ping; | |||||||||||||||||||||||||||||||
| 314 | }; | ||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | # ping() also sets is_connected, unnecessary to check ping return value. | ||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if (not $wire->is_connected) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 318 | 0 | eval { | |||||||||||||||||||||||||||||||
| 319 | 0 | $wire->connect; | |||||||||||||||||||||||||||||||
| 320 | # The below is copy/paste from the drh connect() call. | ||||||||||||||||||||||||||||||||
| 321 | 0 | $dbh->STORE('wire10_thread_id', $wire->{server_thread_id}); | |||||||||||||||||||||||||||||||
| 322 | 0 | $dbh->STORE('wire10_server_version', $wire->{server_version}); | |||||||||||||||||||||||||||||||
| 323 | 0 | $dbh->STORE('Active', 1); | |||||||||||||||||||||||||||||||
| 324 | 0 | $dbh->STORE('AutoCommit', $dbh->FETCH('AutoCommit')); | |||||||||||||||||||||||||||||||
| 325 | }; | ||||||||||||||||||||||||||||||||
| 326 | # Return 0 on failure. | ||||||||||||||||||||||||||||||||
| 327 | 0 | my $error = $wire->get_error_info; | |||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | $dbh->DBI::set_err($error->get_error_code || -1, $error->get_error_message, $error->get_error_state); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$error->get_error_code || -1
MC/DC0%0/1
$error->get_error_code || -1
$error->get_error_code
Truth table0%0/2
A
A= $error->get_error_code
| |||||||||||||||||||||||||||||||||
| 330 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 331 | } elsif ($@) { | ||||||||||||||||||||||||||||||||
| 332 | 0 | $dbh->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 333 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||
| 335 | # Return 1 if connection was reestablished. | ||||||||||||||||||||||||||||||||
| 336 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||
| 338 | # Return -1 if nothing besides a protocol ping was done. | ||||||||||||||||||||||||||||||||
| 339 | 0 | return -1; | |||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 343 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 344 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | $wire->disconnect if defined $wire; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 346 | 0 | $dbh->STORE('wire10_thread_id', undef); | |||||||||||||||||||||||||||||||
| 347 | 0 | $dbh->STORE('Active', 0); | |||||||||||||||||||||||||||||||
| 348 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 352 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | $dbh->disconnect if $dbh->FETCH('Active'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 354 | 0 | $dbh->SUPER::DESTROY; | |||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub last_insert_id { | ||||||||||||||||||||||||||||||
|
Subroutine
last_insert_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 358 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 359 | 0 | return $dbh->FETCH('wire10_insertid') | |||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | # TODO: Support more get_info properties as needed. | ||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub get_info { | ||||||||||||||||||||||||||||||
|
Subroutine
get_info: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 364 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 365 | 0 | my $type = shift; | |||||||||||||||||||||||||||||||
| 366 | # 17: SQL_DBMS_NAME | ||||||||||||||||||||||||||||||||
| 367 | # Difficult to return something intelligent here, the server | ||||||||||||||||||||||||||||||||
| 368 | # only reports a version, not a daemon name in the handshake. | ||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | return 'Wire10' if $type == 17; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | # 18: SQL_DBMS_VER | ||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | return $dbh->FETCH('wire10_server_version') if $type == 18; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 372 | # 29: SQL_IDENTIFIER_QUOTE_CHAR | ||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | return '`' if $type == 29; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 374 | # 41: SQL_CATALOG_NAME_SEPARATOR | ||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | return '.' if $type == 41; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 376 | # 114: SQL_CATALOG_LOCATION | ||||||||||||||||||||||||||||||||
| 377 | # According to MSDN, 0 means "catalog not supported" which is accurate. | ||||||||||||||||||||||||||||||||
| 378 | # (The server happily accepts, discards and prints a catalog named | ||||||||||||||||||||||||||||||||
| 379 | # 'def', though.) | ||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | return 0 if $type == 114; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 381 | # Return undef for unknown and unsupported attributes. | ||||||||||||||||||||||||||||||||
| 382 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | sub take_imp_data { | ||||||||||||||||||||||||||||||
|
Subroutine
take_imp_data: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 386 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||
| 388 | # Finish any active statements (important if streaming enabled). | ||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | for my $sth (@{$dbh->{ChildHandles} || []}) { | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->{'ChildHandles'} || []
MC/DC0%0/1
$dbh->{'ChildHandles'} || []
$dbh->{'ChildHandles'}
Truth table0%0/2
A
A= $dbh->{'ChildHandles'}
| |||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | next unless $sth; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | $sth->finish if $sth->{Active}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||
| 394 | # Take out core driver and remove reference to it. | ||||||||||||||||||||||||||||||||
| 395 | 0 | my $wire = $dbh->FETCH('wire10_driver_dbh'); | |||||||||||||||||||||||||||||||
| 396 | 0 | $dbh->STORE('wire10_driver_dbh', undef); | |||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | # Remove reference to dbh from drh, probably also destroys dbh. | ||||||||||||||||||||||||||||||||
| 399 | 0 | $dbh->SUPER::take_imp_data; | |||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | # Note: It would be nice to serialize or tie the core such that | ||||||||||||||||||||||||||||||||
| 402 | # it can be be shared among interpreters running in different | ||||||||||||||||||||||||||||||||
| 403 | # processes or threads. Unfortunately, neither of the available | ||||||||||||||||||||||||||||||||
| 404 | # modules, Storable and threads::shared, seem to be able to | ||||||||||||||||||||||||||||||||
| 405 | # cope with socket handles: | ||||||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||||||
| 407 | # Storable error: "Can't store GLOB items" | ||||||||||||||||||||||||||||||||
| 408 | # threads::shared error: "Invalid value for shared scalar" | ||||||||||||||||||||||||||||||||
| 409 | # | ||||||||||||||||||||||||||||||||
| 410 | # For now, we just return the core driver and expect that the | ||||||||||||||||||||||||||||||||
| 411 | # caller serialize and deserialize the object if the caller needs | ||||||||||||||||||||||||||||||||
| 412 | # to use it from a different context. | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | # Return the core driver. | ||||||||||||||||||||||||||||||||
| 415 | 0 | return $wire; | |||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | package DBD::Wire10::st; | ||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 424 | 2 | ▶ | use DBI qw(:sql_types); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | 2 | $DBD::Wire10::st::imp_data_size = 0; | |||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | # TODO: Find out if DBI already calls a DBD st constructor somewhere | ||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | sub _constructor { | ||||||||||||||||||||||||||||||
|
Subroutine
_constructor: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 430 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 431 | 0 | my $wire = shift; | |||||||||||||||||||||||||||||||
| 432 | 0 | my $sql = shift; | |||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | 0 | my $ps = $wire->prepare($sql); | |||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | # Store driver handle and prepared statement for later. | ||||||||||||||||||||||||||||||||
| 437 | 0 | $sth->STORE('wire10_driver_sth', $wire); | |||||||||||||||||||||||||||||||
| 438 | 0 | $sth->STORE('wire10_prepared', $ps); | |||||||||||||||||||||||||||||||
| 439 | 0 | $sth->STORE('NUM_OF_PARAMS', $ps->get_marker_count); | |||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | sub bind_param { | ||||||||||||||||||||||||||||||
|
Subroutine
bind_param: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 443 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 444 | 0 | my ($index, $value, $attr) = @_; | |||||||||||||||||||||||||||||||
| 445 | 0 | my $binary = _test_for_binary_flag($sth, $attr); | |||||||||||||||||||||||||||||||
| 446 | 0 | my $ps = $sth->FETCH('wire10_prepared'); | |||||||||||||||||||||||||||||||
| 447 | 0 | $ps->set_parameter($index, $value, $binary); | |||||||||||||||||||||||||||||||
| 448 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | sub _test_for_binary_flag { | ||||||||||||||||||||||||||||||
|
Subroutine
_test_for_binary_flag: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||
| 452 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 453 | 0 | my $attr = shift; | |||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | return 0 unless defined $attr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 455 | 0 | my $binary = Net::Wire10::DATA_BINARY; | |||||||||||||||||||||||||||||||
| 456 | 0 | my $text = Net::Wire10::DATA_TEXT; | |||||||||||||||||||||||||||||||
| 457 | 0 | my $sqltype; | |||||||||||||||||||||||||||||||
| 458 | # May be undefined. | ||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | $sqltype = $attr if ref($attr) eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | $sqltype = $attr->{TYPE} if ref($attr) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if (defined $sqltype) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | return $binary if $sqltype == SQL_BINARY; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | return $binary if $sqltype == SQL_VARBINARY; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | return $binary if $sqltype == SQL_LONGVARBINARY; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | return $binary if $sqltype == SQL_BLOB; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||
| 467 | # For testing Oracle-based code with MySQL. | ||||||||||||||||||||||||||||||||
| 468 | # ORA_BLOB is 113, defined in Oracle.h. | ||||||||||||||||||||||||||||||||
| 469 | 0 | my $oratype; | |||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | $oratype = $attr->{ora_type} if ref($attr) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | return $binary if defined $oratype and $oratype == 113; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $oratype and $oratype == 113
MC/DC0%0/2
defined $oratype and $oratype == 113
defined $oratype
$oratype == 113
Truth table0%0/3
A and B
A= defined $oratypeB= $oratype == 113
| |||||||||||||||||||||||||||||||||
| 472 | 0 | return $text; | |||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||
| 476 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 477 | 0 | my @new_params = @_; | |||||||||||||||||||||||||||||||
| 478 | 0 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||
| 479 | 0 | my $wire = $sth->FETCH('wire10_driver_sth'); | |||||||||||||||||||||||||||||||
| 480 | 0 | my $ps = $sth->FETCH('wire10_prepared'); | |||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | unless (defined($ps)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 483 | 0 | $sth->DBI::set_err(-1, "execute without prepare"); | |||||||||||||||||||||||||||||||
| 484 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | if (scalar(@new_params) > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 488 | 0 | $ps->clear_parameter; | |||||||||||||||||||||||||||||||
| 489 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||
| 490 | 0 | foreach my $p (@new_params) { | |||||||||||||||||||||||||||||||
| 491 | 0 | $ps->set_parameter($i++, $p, 0); | |||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||
| 495 | 0 | my $rowcount = eval { | |||||||||||||||||||||||||||||||
| 496 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | my $stream_results = $sth->FETCH('wire10_streaming') || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$sth->FETCH('wire10_streaming') || 0
MC/DC0%0/1
$sth->FETCH('wire10_streaming') || 0
$sth->FETCH('wire10_streaming')
Truth table0%0/2
A
A= $sth->FETCH('wire10_streaming')
| |||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | my $res = $stream_results ? $ps->stream : $ps->query; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | die if $wire->get_error_info; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||
| 502 | 0 | $sth->STORE('wire10_warning_count', $res->get_warning_count); | |||||||||||||||||||||||||||||||
| 503 | # For backward compatibility and/or do(), store in dbh too. | ||||||||||||||||||||||||||||||||
| 504 | 0 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||
| 505 | 0 | $dbh->STORE('wire10_warning_count', $res->get_warning_count); | |||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | if ($res->has_results) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 508 | 0 | $sth->{wire10_iterator} = $res; | |||||||||||||||||||||||||||||||
| 509 | 0 | my @names = $res->get_column_info("name"); | |||||||||||||||||||||||||||||||
| 510 | 0 | $sth->STORE('NUM_OF_FIELDS', scalar @names); | |||||||||||||||||||||||||||||||
| 511 | 0 | $sth->STORE('NAME', [@names]); | |||||||||||||||||||||||||||||||
| 512 | 0 | my @flags = $res->get_column_info("flags"); | |||||||||||||||||||||||||||||||
| 513 | 0 | my @nullable = map { ! $_ & Net::Wire10::COLUMN_NOT_NULL } @flags; | |||||||||||||||||||||||||||||||
| 514 | 0 | $sth->STORE('NULLABLE', [@nullable]); | |||||||||||||||||||||||||||||||
| 515 | # DBI docs says this is important for bind_columns and bind_cols. | ||||||||||||||||||||||||||||||||
| 516 | 0 | $sth->STORE('Active', 1); | |||||||||||||||||||||||||||||||
| 517 | # Note: Emulate DBD-MySQL by not resetting insertid in dbh (only sth). | ||||||||||||||||||||||||||||||||
| 518 | 0 | $sth->STORE('wire10_insertid', undef); | |||||||||||||||||||||||||||||||
| 519 | 0 | $sth->{wire10_rows} = $res->get_no_of_selected_rows; | |||||||||||||||||||||||||||||||
| 520 | 0 | return $res->get_no_of_selected_rows; | |||||||||||||||||||||||||||||||
| 521 | } else { | ||||||||||||||||||||||||||||||||
| 522 | 0 | $sth->{wire10_iterator} = undef; | |||||||||||||||||||||||||||||||
| 523 | 0 | $sth->STORE('NUM_OF_FIELDS', undef); | |||||||||||||||||||||||||||||||
| 524 | 0 | $sth->STORE('NAME', undef); | |||||||||||||||||||||||||||||||
| 525 | 0 | $sth->STORE('NULLABLE', undef); | |||||||||||||||||||||||||||||||
| 526 | 0 | my $insertid; | |||||||||||||||||||||||||||||||
| 527 | 0 | eval { | |||||||||||||||||||||||||||||||
| 528 | 0 | $insertid = $res->get_insert_id; | |||||||||||||||||||||||||||||||
| 529 | }; | ||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 531 | # If the insert_id is too big for this Perl to handle, | ||||||||||||||||||||||||||||||||
| 532 | # extract it using an alternate method. | ||||||||||||||||||||||||||||||||
| 533 | 0 | my $res = $wire->query('SELECT LAST_INSERT_ID()'); | |||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | $insertid = $res->next_array()->[0] || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->next_array->[0] || 0
MC/DC0%0/1
$res->next_array->[0] || 0
$res->next_array->[0]
Truth table0%0/2
A
A= $res->next_array->[0]
| |||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||
| 536 | 0 | $sth->STORE('wire10_insertid', $insertid); | |||||||||||||||||||||||||||||||
| 537 | # For backward compatibility and/or do(), store in dbh too. | ||||||||||||||||||||||||||||||||
| 538 | 0 | $dbh->STORE('wire10_insertid', $insertid); | |||||||||||||||||||||||||||||||
| 539 | 0 | $sth->{wire10_rows} = $res->get_no_of_affected_rows; | |||||||||||||||||||||||||||||||
| 540 | 0 | return $res->get_no_of_affected_rows; | |||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||
| 542 | }; | ||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||
| 544 | 0 | my $error = $wire->get_error_info; | |||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | $sth->DBI::set_err($error->get_error_code || -1, $error->get_error_message, $error->get_error_state); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$error->get_error_code || -1
MC/DC0%0/1
$error->get_error_code || -1
$error->get_error_code
Truth table0%0/2
A
A= $error->get_error_code
| |||||||||||||||||||||||||||||||||
| 547 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 548 | } elsif ($@) { | ||||||||||||||||||||||||||||||||
| 549 | 0 | $sth->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 550 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | return $rowcount ? $rowcount : '0E0'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | sub cancel { | ||||||||||||||||||||||||||||||
|
Subroutine
cancel: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 557 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 558 | 0 | my $wire = $sth->FETCH('wire10_driver_sth'); | |||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||
| 560 | 0 | eval { | |||||||||||||||||||||||||||||||
| 561 | 0 | $wire->cancel; | |||||||||||||||||||||||||||||||
| 562 | }; | ||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 565 | 0 | $sth->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 566 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||
| 569 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | sub finish { | ||||||||||||||||||||||||||||||
|
Subroutine
finish: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 573 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 574 | 0 | my $dbh = $sth->{Database}; | |||||||||||||||||||||||||||||||
| 575 | # If in streaming mode, flush remaining results. | ||||||||||||||||||||||||||||||||
| 576 | 0 | my $iterator = $sth->{wire10_iterator}; | |||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | $iterator->spool if defined $iterator; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 578 | 0 | $sth->{wire10_iterator} = undef; | |||||||||||||||||||||||||||||||
| 579 | 0 | $sth->STORE('Active', 0); | |||||||||||||||||||||||||||||||
| 580 | 0 | $sth->SUPER::finish; | |||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | sub fetchrow_arrayref { | ||||||||||||||||||||||||||||||
|
Subroutine
fetchrow_arrayref: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 584 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||
| 586 | 0 | my $iterator = $sth->FETCH('wire10_iterator'); | |||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | unless ($iterator) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | if ($sth->FETCH('Warn')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 589 | 0 | warn 'fetch() without execute(), previous execute() failed, executed query does not have results, or last row was already fetched'; | |||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||
| 591 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||
| 594 | 0 | my $row = undef; | |||||||||||||||||||||||||||||||
| 595 | 0 | eval { | |||||||||||||||||||||||||||||||
| 596 | 0 | $row = $iterator->next_array; | |||||||||||||||||||||||||||||||
| 597 | }; | ||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 599 | 0 | $sth->DBI::set_err(-1, $@); | |||||||||||||||||||||||||||||||
| 600 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | if (! $row) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 603 | 0 | $sth->finish; | |||||||||||||||||||||||||||||||
| 604 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | if ($sth->FETCH('ChopBlanks')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 608 | 0 | map {s/\s+$//} @$row; | |||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||
| 611 | 0 | return $sth->_set_fbav($row); | |||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||
| 614 | # required alias for fetchrow_arrayref | ||||||||||||||||||||||||||||||||
| 615 | 2 | *fetch = \&fetchrow_arrayref; | |||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | sub rows { | ||||||||||||||||||||||||||||||
|
Subroutine
rows: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 618 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 619 | 0 | my $rows = $sth->FETCH('wire10_rows'); | |||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | return $rows unless $rows == -1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 621 | 0 | return $sth->SUPER::rows; | |||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 625 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 626 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | return $sth->{NAME} if $key eq 'NAME'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | return $sth->{NULLABLE} if $key eq 'NULLABLE'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | return $sth->{$key} if $key =~ /^wire10_/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 631 | 0 | return $sth->SUPER::FETCH($key); | |||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 635 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 636 | 0 | my ($key, $value) = @_; | |||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | if ($key eq 'NAME') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 639 | 0 | $sth->{NAME} = $value; | |||||||||||||||||||||||||||||||
| 640 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | if ($key eq 'NULLABLE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 643 | 0 | $sth->{NULLABLE} = $value; | |||||||||||||||||||||||||||||||
| 644 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | if ($key =~ /^wire10_/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 647 | 0 | $sth->{$key} = $value; | |||||||||||||||||||||||||||||||
| 648 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||
| 651 | 0 | return $sth->SUPER::STORE($key, $value); | |||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 655 | 0 | my $sth = shift; | |||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | $sth->finish if $sth->FETCH('Active'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 657 | 0 | $sth->SUPER::DESTROY; | |||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||
| 662 | 2 | 1; | |||||||||||||||||||||||||||||||
| 663 | __END__ | ||||||||||||||||||||||||||||||||