| 1 | package DBIO::MSSQL::Storage::ODBC; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Support for Microsoft SQL Server via DBD::ODBC | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | our $VERSION = '0.900004'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use base qw/ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | DBIO::Storage::DBI::ODBC | ||||||||||||||||||||||||||||||||||||||||||
| 11 | DBIO::MSSQL::Storage | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | /; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 15 | ▶ | use DBIO::Exception (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 15 | ▶ | use DBIO::Util qw(is_plain_value); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 15 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # karr k61. DBI's LongReadLen is 80, and DBD::ODBC reads a LOB value (TEXT, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # NTEXT, VARCHAR(MAX), NVARCHAR(MAX), VARBINARY(MAX), IMAGE, XML) only up to | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # it. Beyond it the fetch throws -- but exactly AT the boundary it does not: | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # measured with DBD::ODBC 1.61 over FreeTDS 1.3.17, a VARCHAR(MAX), TEXT or | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # NTEXT value of LongReadLen + 1 characters comes back with its last | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # character replaced by a NUL, and an NVARCHAR(MAX) value of exactly | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # LongReadLen characters too, without an error. A LongReadLen that no value | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # reaches takes the boundary out of reach. It is not free: see the POD, "The | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # price of 1 GiB". It is the default only: the connect info's LongReadLen is | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # the regulator, as it was. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 15 | my $LONG_READ_LEN = 1073741824; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # On the handle, after the connect, as the FreeTDS class of DBIO::Sybase does | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # for the text size: the storage becomes this class at its first use, after | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # the connect info was read and the first connection made, so the attribute | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # defaults cannot carry it. Every connection gets it, a reconnect too. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 11 | ▶ | sub _run_connection_actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_connection_actions: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | my $dbh = $self->_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | $dbh->{LongReadLen} = $LONG_READ_LEN | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | ▶ | unless exists $self->_dbio_connect_attributes->{LongReadLen}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | # karr k81 (reading, the other half of k58). A DBD::ODBC without Unicode | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # support hands every SQL_CHAR value back as the bytes the client library | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # made of it -- UTF-8 when the ClientCharset is UTF-8, which is what the | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # write path requires before it sends a string beyond ASCII -- without the | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # UTF-8 flag: an a-umlaut read back is two characters, a CJK character | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # three. With odbc_utf8_on the driver decodes them. Set only on the | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # connection that was asked (the same question as for writing) and when | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # the connect info does not say; a DBD::ODBC with Unicode support decodes | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # by itself. Binary columns are not SQL_CHAR and stay bytes. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 11 | ▶ | unless ( $dbh->{odbc_has_unicode} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dbh->{"odbc_has_unicode"} or exists $self->_dbio_connect_attributes->{"odbc_utf8_on"}
MC/DC100%2/2
$dbh->{"odbc_has_unicode"} or exists $self->_dbio_connect_attributes->{"odbc_utf8_on"}
$dbh->{"odbc_has_unicode"}
exists $self->_dbio_connect_attributes->{"odbc_utf8_on"}
Truth table100%3/3
A or B
A= $dbh->{"odbc_has_unicode"}B= exists $self->_dbio_connect_attributes->{"odbc_utf8_on"}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | or exists $self->_dbio_connect_attributes->{odbc_utf8_on} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | my $utf8 = eval { $self->_client_charset_is_utf8($dbh) }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | ▶ | $dbh->{odbc_utf8_on} = 1 if $utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 11 | return $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # karr k58. The columns a Unicode value is bound for (see STRINGS BEYOND THE | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # CODE PAGE): those that are NCHAR, NVARCHAR or NTEXT ON THE SERVER, which is | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # what DBIO::MSSQL::DDL deploys the declared type as (_server_data_type): a | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # 'text', 'varchar', 'string' or 'char' column is national too. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 43 | ▶ | sub _is_national_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_national_data_type: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 43 | my ($self, $data_type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 43 | $data_type = $self->_server_data_type($data_type); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 43 | ▶ | return 0 unless defined $data_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 43 | ▶ | return $data_type =~ /\A \s* | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | (?: nchar | nvarchar | ntext | ||||||||||||||||||||||||||||||||||||||||||
| 77 | | national \s+ char (?: acter )? (?: \s+ varying )? ) | ||||||||||||||||||||||||||||||||||||||||||
| 78 | \s* (?: \( [^)]* \) )? \s* \z/xi ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 56 | ▶ | sub bind_attribute_by_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_attribute_by_data_type: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 56 | my ($self, $data_type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 56 | ▶ | return DBI::SQL_LONGVARBINARY() if $self->_is_binary_data_type($data_type); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | # The one Unicode type that carries a value whole at every size | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # (SQL_WVARCHAR stops at 4000 characters without an error, SQL_WCHAR pads). | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 43 | ▶ | return DBI::SQL_WLONGVARCHAR() if $self->_is_national_data_type($data_type); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 13 | return $self->next::method($data_type); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Does the connection read what the driver sends as UTF-8? A DBD::ODBC without | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # Unicode support sends a string as bytes (the UTF-8 form of a string with the | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # flag on) and the client library reads them in its ClientCharset. If that is | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # not UTF-8 a string beyond ASCII is stored as other characters and nothing | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # says so. The connection is asked what it holds for an a-umlaut, as Unicode | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # (SQL_WLONGVARCHAR, so the code page of the server is no part of the | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # question): 228, or the first byte of its UTF-8 form. Once per handle. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 23 | ▶ | sub _client_charset_is_utf8 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_client_charset_is_utf8: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 23 | my ($self, $dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 23 | ▶ | return 1 if $dbh->{odbc_has_unicode}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 22 | my $seen = $self->{_odbc_client_charset_utf8}; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 22 | ▶ | return $seen->[1] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$seen and defined $seen->[0] and $seen->[0] == $dbh
$seen and defined $seen->[0]
MC/DC33%1/3
$seen and defined $seen->[0] and $seen->[0] == $dbh
$seen
defined $seen->[0]
$seen->[0] == $dbh
Truth table50%2/4
A and B and C
A= $seenB= defined $seen->[0]C= $seen->[0] == $dbh
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | if $seen and defined $seen->[0] and $seen->[0] == $dbh; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | my $probe = "\x{E4}"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | utf8::upgrade($probe); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | my $sth = $dbh->prepare('SELECT UNICODE(CAST(? AS NVARCHAR(10)))'); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | $sth->bind_param(1, $probe, DBI::SQL_WLONGVARCHAR()); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 7 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | my ($code) = $sth->fetchrow_array; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | $sth->finish; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | ▶ | my $is_utf8 = ( defined $code and $code == 0xE4 ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $code and $code == 228
MC/DC100%2/2
defined $code and $code == 228
defined $code
$code == 228
Truth table100%3/3
A and B
A= defined $codeB= $code == 228
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | $self->{_odbc_client_charset_utf8} = [ $dbh, $is_utf8 ]; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 7 | Scalar::Util::weaken( $self->{_odbc_client_charset_utf8}[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 7 | return $is_utf8; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # What is told, never the value. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | ▶ | sub _refuse_client_charset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refuse_client_charset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | my ($self, $what) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | $self->throw_exception(sprintf | |||||||||||||||||||||||||||||||||||||||||
| 131 | 'Cannot send this statement through DBD::ODBC: %s has a character ' | ||||||||||||||||||||||||||||||||||||||||||
| 132 | . 'beyond ASCII, and the client character set of the ODBC driver is not ' | ||||||||||||||||||||||||||||||||||||||||||
| 133 | . 'UTF-8. This DBD::ODBC is built without Unicode support: it sends the ' | ||||||||||||||||||||||||||||||||||||||||||
| 134 | . 'UTF-8 bytes of a string, which the driver would read in its own ' | ||||||||||||||||||||||||||||||||||||||||||
| 135 | . 'character set and store as other characters (an a-umlaut as two), ' | ||||||||||||||||||||||||||||||||||||||||||
| 136 | . 'without an error. Set the client character set to UTF-8: ' | ||||||||||||||||||||||||||||||||||||||||||
| 137 | . 'ClientCharset=UTF-8 in the DSN (FreeTDS), or a UTF-8 locale.', | ||||||||||||||||||||||||||||||||||||||||||
| 138 | $what, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # The text the driver is given for a value of a text column: the string with | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # its characters as UTF-8 (the flag on) when there is one beyond ASCII; undef | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # for a value that has none, or is none (NULL, bind_inout, an object that is | ||||||||||||||||||||||||||||||||||||||||||
| 145 | # not a plain value -- core binds that untouched). | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 28 | ▶ | sub _beyond_ascii_as_characters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_beyond_ascii_as_characters: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 28 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 28 | ▶ | return undef if not defined $value or ref $value eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or ref $value eq "SCALAR"
MC/DC50%1/2
not defined $value or ref $value eq "SCALAR"
not defined $value
ref $value eq "SCALAR"
Truth table66%2/3
not(A) or B
A= not defined $valueB= ref $value eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 27 | ▶ | if (length ref $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | return undef unless is_plain_value $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $value = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 27 | ▶ | return undef unless $value =~ /[^\x00-\x7F]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | # A string is its characters, whatever form Perl holds it in: an a-umlaut | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # made with "\x{E4}" has no UTF-8 flag, and the driver would take its one | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # byte for a broken UTF-8 sequence. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 15 | utf8::upgrade($value); | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 15 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | # The bind values of a statement with the text ones beyond ASCII as | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # characters (UTF-8 flag on); the list itself when there is none. A binary | ||||||||||||||||||||||||||||||||||||||||||
| 168 | # value is bytes and left alone. Asks, once per handle, whether the client | ||||||||||||||||||||||||||||||||||||||||||
| 169 | # character set can take them, and refuses when it cannot. | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 20 | ▶ | sub _text_binds_as_characters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text_binds_as_characters: called CC=11 SCAR=24.4
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 20 | my ($self, $dbh, $bind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 20 | my ($i, $found, @new) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 20 | ▶ | for my $b (@{ $bind || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$bind || []
MC/DC0%0/1
$bind || []
$bind
Truth table50%1/2
A
A= $bind
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 27 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 27 | my ($attrs, $value) = @$b; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | my $characters = ( ref $attrs eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 27 | ▶ | and $self->_is_binary_data_type( $attrs->{sqlt_datatype} ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $attrs eq "HASH" and $self->_is_binary_data_type($attrs->{"sqlt_datatype"})
MC/DC50%1/2
ref $attrs eq "HASH" and $self->_is_binary_data_type($attrs->{"sqlt_datatype"})
ref $attrs eq "HASH"
$self->_is_binary_data_type($attrs->{"sqlt_datatype"})
Truth table66%2/3
A and B
A= ref $attrs eq "HASH"B= $self->_is_binary_data_type($attrs->{"sqlt_datatype"})
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | ? undef | ||||||||||||||||||||||||||||||||||||||||||
| 181 | : _beyond_ascii_as_characters($value); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 27 | ▶ | if (defined $characters) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 13 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 185 | $self->_refuse_client_charset( | ||||||||||||||||||||||||||||||||||||||||||
| 186 | "bind value $i of " . scalar(@$bind) | ||||||||||||||||||||||||||||||||||||||||||
| 187 | . ( ref $attrs eq 'HASH' and defined $attrs->{dbic_colname} | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 13 | ▶ | ? " (column '$attrs->{dbic_colname}')" : '' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $attrs eq 'HASH' && (defined $attrs->{'dbic_colname'} ? " (column '$attrs->{'dbic_colname'}')" : '')
MC/DC0%0/2
ref $attrs eq 'HASH' && (defined $attrs->{'dbic_colname'} ? " (column '$attrs->{'dbic_colname'}')" : '')
ref $attrs eq 'HASH'
(defined $attrs->{'dbic_colname'} ? " (column '$attrs->{'dbic_colname'}')" : '')
Truth table33%1/3
A && B
A= ref $attrs eq 'HASH'B= (defined $attrs->{'dbic_colname'} ? " (column '$attrs->{'dbic_colname'}')" : '')
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | ) unless $self->_client_charset_is_utf8($dbh); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 24 | ▶ | push @new, defined $characters ? [ $attrs, $characters ] : $b; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 17 | ▶ | return $found ? \@new : $bind; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # populate in void context hands the storage rows, not bind values: the same | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # for a text column's value beyond ASCII (and for the binds of a literal). | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | sub _text_rows_as_characters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text_rows_as_characters: called CC=10 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | my ($self, $source, $cols, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | my $colinfos = $source->columns_info($cols); | |||||||||||||||||||||||||||||||||||||||||
| 204 | my @text = map { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | ▶ | $self->_is_binary_data_type( $colinfos->{ $cols->[$_] }{data_type} ) ? 0 : 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | } 0 .. $#$cols; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||
| 209 | my @rows = map { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | my @row = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 7 | for my $i (0 .. $#row) { | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if (ref $row[$i] eq 'REF' and ref ${ $row[$i] } eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $row[$i] eq "REF" and ref ${$row[$i];} eq "ARRAY"
MC/DC0%0/2
ref $row[$i] eq "REF" and ref ${$row[$i];} eq "ARRAY"
ref $row[$i] eq "REF"
ref ${$row[$i];} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $row[$i] eq "REF"B= ref ${$row[$i];} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my ($sql, @bind) = @${ $row[$i] }; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $resolved = $self->_resolve_bindattrs($source, \@bind, $colinfos); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $as_characters = $self->_text_binds_as_characters( | |||||||||||||||||||||||||||||||||||||||||
| 217 | $self->_get_dbh, $resolved, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ($as_characters != $resolved) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $row[$i] = \[ $sql, @$as_characters ]; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | elsif ($text[$i]) { | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | my $characters = _beyond_ascii_as_characters($row[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 7 | ▶ | next unless defined $characters; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | ▶ | $self->_refuse_client_charset("a value for the column '$cols->[$i]'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | unless $self->_client_charset_is_utf8( $self->_get_dbh ); | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $row[$i] = $characters; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | \@row; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } @$data; | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | ▶ | return $found ? \@rows : $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | # The bind values of a statement, those of a binary column as their bytes; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # the list itself when there is none. Throws for a character above 255. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 17 | ▶ | sub _binary_binds_as_bytes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_binary_binds_as_bytes: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 17 | my ($self, $bind) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | return $bind unless grep { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | ref $_->[0] eq 'HASH' and $self->_is_binary_data_type( $_->[0]{sqlt_datatype} ) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 17 | ▶ | } @{ $bind || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
ref $_->[0] eq 'HASH' && $self->_is_binary_data_type($_->[0]{'sqlt_datatype'})
$bind || []
MC/DC50%1/2
ref $_->[0] eq 'HASH' && $self->_is_binary_data_type($_->[0]{'sqlt_datatype'})
ref $_->[0] eq 'HASH'
$self->_is_binary_data_type($_->[0]{'sqlt_datatype'})
MC/DC0%0/1
$bind || []
$bind
Truth table66%2/3
A && B
A= ref $_->[0] eq 'HASH'B= $self->_is_binary_data_type($_->[0]{'sqlt_datatype'})
Truth table50%1/2
A
A= $bind
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | return [ map { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | ( ref $_->[0] eq 'HASH' | |||||||||||||||||||||||||||||||||||||||||
| 253 | and $self->_is_binary_data_type( $_->[0]{sqlt_datatype} ) | ||||||||||||||||||||||||||||||||||||||||||
| 254 | and ref $_->[1] ne 'SCALAR' ) # bind_inout | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | ▶ | ? [ $_->[0], $self->_binary_value_bytes( $_->[1], $_->[0]{dbic_colname} ) ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $_->[0] eq "HASH" and $self->_is_binary_data_type($_->[0]{"sqlt_datatype"}) and ref $_->[1] ne "SCALAR"
ref $_->[0] eq "HASH" and $self->_is_binary_data_type($_->[0]{"sqlt_datatype"})
MC/DC33%1/3
ref $_->[0] eq "HASH" and $self->_is_binary_data_type($_->[0]{"sqlt_datatype"}) and ref $_->[1] ne "SCALAR"
ref $_->[0] eq "HASH"
$self->_is_binary_data_type($_->[0]{"sqlt_datatype"})
ref $_->[1] ne "SCALAR"
Truth table50%2/4
A and B and C
A= ref $_->[0] eq "HASH"B= $self->_is_binary_data_type($_->[0]{"sqlt_datatype"})C= ref $_->[1] ne "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | : $_ | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } @$bind ]; | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # ADR 0040, karr k71. Measured live 2026-10-19 (MSSQL 2022, DBD::ODBC 1.61 / | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # tdsodbc 1.3.17): the base class's three round-trips do not give a plan over | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # DBD::ODBC. The prepared SET SHOWPLAN_ALL ON does not outlive its prepare, so | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # the explained query RUNS and its own rows come back as the "plan" -- well | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # formed, no error, wrong. A silently wrong answer is refused. DBD::Sybase | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # without placeholders returns the 18-column plan (base class, unchanged). | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | sub _explain_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_explain_query: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | DBIO::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 270 | 'DBIO::MSSQL: explain is refused over DBD::ODBC: no plan over ODBC. SQL Server\'s ' | ||||||||||||||||||||||||||||||||||||||||||
| 271 | . 'SET SHOWPLAN_ALL does not take effect over a prepared statement there, ' | ||||||||||||||||||||||||||||||||||||||||||
| 272 | . 'so the query would run and its own rows would be returned as the plan. ' | ||||||||||||||||||||||||||||||||||||||||||
| 273 | . 'Connect through DBD::Sybase without placeholders for a plan ' | ||||||||||||||||||||||||||||||||||||||||||
| 274 | . '(DBIO::MSSQL::Storage::Sybase), or read it in SQL Server Management ' | ||||||||||||||||||||||||||||||||||||||||||
| 275 | . 'Studio.' | ||||||||||||||||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # Ahead of the trace and the prepare (core's _dbh_execute, _dbh_prepare), so | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # that a value that is no binary value is refused before anything is sent. | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 20 | ▶ | sub _dbh_execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_execute: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 20 | my ($self, $dbh, $sql, $bind, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 20 | return $self->next::method( | |||||||||||||||||||||||||||||||||||||||||
| 285 | $dbh, $sql, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | $self->_binary_binds_as_bytes( $self->_text_binds_as_characters($dbh, $bind) ), | ||||||||||||||||||||||||||||||||||||||||||
| 287 | @rest, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub _dbh_prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbh_prepare: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my ($self, $dbh, $sql, $bind, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $self->next::method( | |||||||||||||||||||||||||||||||||||||||||
| 295 | $dbh, $sql, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | $self->_binary_binds_as_bytes( $self->_text_binds_as_characters($dbh, $bind) ), | ||||||||||||||||||||||||||||||||||||||||||
| 297 | @rest, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | sub _insert_bulk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_bulk: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | my ($self, $source, $cols, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | $data = $self->_text_rows_as_characters($source, $cols, $data); | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | my ($as_bytes) = $self->_bulk_binary_values_as_bytes($source, $cols, $data); | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | return $self->next::method($source, $cols, $as_bytes); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | __END__ | ||||||||||||||||||||||||||||||||||||||||||