MSSQL/Storage/ODBC.pm

filter: Statementstmt 83.7% 108 / 129 Branchbran 76.5% 49 / 64 Conditioncond 55.8% 24 / 43 MC/DCmcdc 34.6% 9 / 26 Subroutinesub 90.9% 20 / 22 Podpod 100% 1 / 1 totaltotal 74.0% 211 / 285 CC 51 SCAR 24.7
CC
51
Cov
77%
_dbi_handle_error
56.0
_text_rows_as_characters
13.2
_text_binds_as_characters
11.5
CRAP 11.8
« MSSQL/Util.pm ↑ Summary MSSQL/Storage/Sybase.pm »
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.900007';
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
BranchTrueFalseTotal
unless exists $self->_dbio_connect_attributes->{"LongReadLen"} 11 0 11
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
BranchTrueFalseTotal
unless ($dbh->{"odbc_has_unicode"} or exists $self->_dbio_connect_attributes->{"odbc_utf8_on"}) 8 3 11
Condition100%3/3
$dbh->{"odbc_has_unicode"} or exists $self->_dbio_connect_attributes->{"odbc_utf8_on"}
l!l&&r!l&&!r
218
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"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $utf8 3 5 8
59 }
60  
61 11 return $self->next::method(@_);
62 }
63  
64 # The text of DBD::ODBC carries no server message number, and the words of a
65 # message change with the language of the session. The diagnostic records of
66 # the failing handle do carry it, and they are gone once the handler is left,
67 # so they are put where the masking of the text (_mask_error_values) finds
68 # them. A handle without records (a $dbh->do with binds) leaves the SQLSTATE
69 # behind the text to decide.
70 0 ▶sub _dbi_handle_error {
Subroutine _dbi_handle_error: not called CC=7 SCAR=40.3
71 0 my ($self, $msg, $h) = @_;
72  
73 0 my @diag;
74 0 ▶ if (Scalar::Util::blessed($h) and $h->can('odbc_getdiagrec')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($h) and $h->can("odbc_getdiagrec")) 0 0 0
Condition0%0/3
builtin::blessed($h) and $h->can("odbc_getdiagrec")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($h) and $h->can("odbc_getdiagrec")
builtin::blessed($h) $h->can("odbc_getdiagrec")
Truth table0%0/3
A and B
A= builtin::blessed($h)B= $h->can("odbc_getdiagrec")
ABresult
0X0
100
111
75 0 for my $i (1 .. 20) {
76 0 ▶ my @rec = eval { $h->odbc_getdiagrec($i) } or last;
Branch: 1 branch
BranchTrueFalseTotal
my(@rec) = eval { do { $h->odbc_getdiagrec($i) } } or last 0 0 0
77 0 ▶ push @diag, [ $rec[1], $rec[2] ] if defined $rec[1] and defined $rec[2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $rec[1] and defined $rec[2] 0 0 0
Condition0%0/3
defined $rec[1] and defined $rec[2]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rec[1] and defined $rec[2]
defined $rec[1] defined $rec[2]
Truth table0%0/3
A and B
A= defined $rec[1]B= defined $rec[2]
ABresult
0X0
100
111
78 }
79 }
80  
81 0 local $self->{_dbio_server_diag} = \@diag;
82 0 return $self->next::method($msg, $h, @_[3 .. $#_]);
83 }
84  
85 # karr k58. The columns a Unicode value is bound for (see STRINGS BEYOND THE
86 # CODE PAGE): those that are NCHAR, NVARCHAR or NTEXT ON THE SERVER, which is
87 # what DBIO::MSSQL::DDL deploys the declared type as (_server_data_type): a
88 # 'text', 'varchar', 'string' or 'char' column is national too.
89 43 ▶sub _is_national_data_type {
Subroutine _is_national_data_type: called CC=3 SCAR=11.0
90 43 my ($self, $data_type) = @_;
91  
92 43 $data_type = $self->_server_data_type($data_type);
93  
94 43 ▶ return 0 unless defined $data_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_type 0 43 43
95  
96 43 ▶ return $data_type =~ /\A \s*
Branch: 1 branch
BranchTrueFalseTotal
$data_type =~ /\A \s* (?: nchar | nvarchar | ntext | national \s+ char (?: acter )? (?: \s+ varying )? ) \s* (?: \( [^)]* \) )? \s* \z/xi ? : 30 13 43
97 (?: nchar | nvarchar | ntext
98 | national \s+ char (?: acter )? (?: \s+ varying )? )
99 \s* (?: \( [^)]* \) )? \s* \z/xi ? 1 : 0;
100 }
101  
102 56 ▶sub bind_attribute_by_data_type {
Subroutine bind_attribute_by_data_type: called CC=3 SCAR=11.0
Pod documented
103 56 my ($self, $data_type) = @_;
104  
105 56 ▶ return DBI::SQL_LONGVARBINARY() if $self->_is_binary_data_type($data_type);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_binary_data_type($data_type) 13 43 56
106  
107 # The one Unicode type that carries a value whole at every size
108 # (SQL_WVARCHAR stops at 4000 characters without an error, SQL_WCHAR pads).
109 43 ▶ return DBI::SQL_WLONGVARCHAR() if $self->_is_national_data_type($data_type);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_national_data_type($data_type) 30 13 43
110  
111 13 return $self->next::method($data_type);
112 }
113  
114 # Does the connection read what the driver sends as UTF-8? A DBD::ODBC without
115 # Unicode support sends a string as bytes (the UTF-8 form of a string with the
116 # flag on) and the client library reads them in its ClientCharset. If that is
117 # not UTF-8 a string beyond ASCII is stored as other characters and nothing
118 # says so. The connection is asked what it holds for an a-umlaut, as Unicode
119 # (SQL_WLONGVARCHAR, so the code page of the server is no part of the
120 # question): 228, or the first byte of its UTF-8 form. Once per handle.
121 23 ▶sub _client_charset_is_utf8 {
Subroutine _client_charset_is_utf8: called CC=7 SCAR=19.5
122 23 my ($self, $dbh) = @_;
123  
124 23 ▶ return 1 if $dbh->{odbc_has_unicode};
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"odbc_has_unicode"} 1 22 23
125  
126 22 my $seen = $self->{_odbc_client_charset_utf8};
127 22 ▶ return $seen->[1]
Branch: 1 branch
BranchTrueFalseTotal
if $seen and defined $seen->[0] and $seen->[0] == $dbh 14 8 22
Condition66%4/6
$seen and defined $seen->[0] and $seen->[0] == $dbh
!ll&&!rl&&r
8014
$seen and defined $seen->[0]
!ll&&!rl&&r
8014
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
ABCresult
0XX0
10X0
1100
1111
128 if $seen and defined $seen->[0] and $seen->[0] == $dbh;
129  
130 8 my $probe = "\x{E4}";
131 8 utf8::upgrade($probe);
132  
133 8 my $sth = $dbh->prepare('SELECT UNICODE(CAST(? AS NVARCHAR(10)))');
134 7 $sth->bind_param(1, $probe, DBI::SQL_WLONGVARCHAR());
135 7 $sth->execute;
136 7 my ($code) = $sth->fetchrow_array;
137 7 $sth->finish;
138  
139 7 ▶ my $is_utf8 = ( defined $code and $code == 0xE4 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $code && $code == 228 ? : 3 4 7
Condition100%3/3
defined $code and $code == 228
!ll&&!rl&&r
223
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
ABresult
0X0
100
111
140  
141 7 $self->{_odbc_client_charset_utf8} = [ $dbh, $is_utf8 ];
142 7 Scalar::Util::weaken( $self->{_odbc_client_charset_utf8}[0] );
143  
144 7 return $is_utf8;
145 }
146  
147 # What is told, never the value.
148 4 ▶sub _refuse_client_charset {
Subroutine _refuse_client_charset: called CC=1 SCAR=0.0
149 4 my ($self, $what) = @_;
150  
151 4 $self->throw_exception(sprintf
152 'Cannot send this statement through DBD::ODBC: %s has a character '
153 . 'beyond ASCII, and the client character set of the ODBC driver is not '
154 . 'UTF-8. This DBD::ODBC is built without Unicode support: it sends the '
155 . 'UTF-8 bytes of a string, which the driver would read in its own '
156 . 'character set and store as other characters (an a-umlaut as two), '
157 . 'without an error. Set the client character set to UTF-8: '
158 . 'ClientCharset=UTF-8 in the DSN (FreeTDS), or a UTF-8 locale.',
159 $what,
160 );
161 }
162  
163 # The text the driver is given for a value of a text column: the string with
164 # its characters as UTF-8 (the flag on) when there is one beyond ASCII; undef
165 # for a value that has none, or is none (NULL, bind_inout, an object that is
166 # not a plain value -- core binds that untouched).
167 28 ▶sub _beyond_ascii_as_characters {
Subroutine _beyond_ascii_as_characters: called CC=6 SCAR=19.6
168 28 my $value = shift;
169  
170 28 ▶ return undef if not defined $value or ref $value eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value eq "SCALAR" 1 27 28
Condition66%2/3
not defined $value or ref $value eq "SCALAR"
l!l&&r!l&&!r
1027
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"
ABresult
1X1
011
000
171  
172 27 ▶ if (length ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (length ref $value) 0 27 27
173 0 ▶ return undef unless is_plain_value $value;
Branch: 1 branch
BranchTrueFalseTotal
unless &is_plain_value($value) 0 0 0
174 0 $value = "$value";
175 }
176  
177 27 ▶ return undef unless $value =~ /[^\x00-\x7F]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /[^\x00-\x7F]/ 12 15 27
178  
179 # A string is its characters, whatever form Perl holds it in: an a-umlaut
180 # made with "\x{E4}" has no UTF-8 flag, and the driver would take its one
181 # byte for a broken UTF-8 sequence.
182 15 utf8::upgrade($value);
183  
184 15 return $value;
185 }
186  
187 # The bind values of a statement with the text ones beyond ASCII as
188 # characters (UTF-8 flag on); the list itself when there is none. A binary
189 # value is bytes and left alone. Asks, once per handle, whether the client
190 # character set can take them, and refuses when it cannot.
191 20 ▶sub _text_binds_as_characters {
Subroutine _text_binds_as_characters: called CC=11 SCAR=24.4
192 20 my ($self, $dbh, $bind) = @_;
193  
194 20 my ($i, $found, @new) = (0, 0);
195 20 ▶ for my $b (@{ $bind || [] }) {
Condition50%1/2
$bind || []
l!l
200
MC/DC0%0/1
$bind || []
$bind
Truth table50%1/2
A
A= $bind
Aresult
11
00
196 27 $i++;
197 27 my ($attrs, $value) = @$b;
198  
199 my $characters = ( ref $attrs eq 'HASH'
200 27 ▶ and $self->_is_binary_data_type( $attrs->{sqlt_datatype} ) )
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq 'HASH' && $self->_is_binary_data_type($attrs->{'sqlt_datatype'}) ? : 6 21 27
Condition66%2/3
ref $attrs eq "HASH" and $self->_is_binary_data_type($attrs->{"sqlt_datatype"})
!ll&&!rl&&r
0216
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"})
ABresult
0X0
100
111
201 ? undef
202 : _beyond_ascii_as_characters($value);
203  
204 27 ▶ if (defined $characters) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $characters) 13 14 27
205 13 $found = 1;
206 $self->_refuse_client_charset(
207 "bind value $i of " . scalar(@$bind)
208 . ( ref $attrs eq 'HASH' and defined $attrs->{dbic_colname}
209 13 ▶ ? " (column '$attrs->{dbic_colname}')" : '' )
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_client_charset_is_utf8($dbh) 3 10 13
defined $attrs->{'dbic_colname'} ? : 3 0 3
Condition33%1/3
ref $attrs eq 'HASH' && (defined $attrs->{'dbic_colname'} ? " (column '$attrs->{'dbic_colname'}')" : '')
!ll&&!rl&&r
003
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'}')" : '')
ABresult
0X0
100
111
210 ) unless $self->_client_charset_is_utf8($dbh);
211 }
212  
213 24 ▶ push @new, defined $characters ? [ $attrs, $characters ] : $b;
Branch: 1 branch
BranchTrueFalseTotal
defined $characters ? : 10 14 24
214 }
215  
216 17 ▶ return $found ? \@new : $bind;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 6 11 17
217 }
218  
219 # populate in void context hands the storage rows, not bind values: the same
220 # for a text column's value beyond ASCII (and for the binds of a literal).
221 4 ▶sub _text_rows_as_characters {
Subroutine _text_rows_as_characters: called CC=10 SCAR=25.8
222 4 my ($self, $source, $cols, $data) = @_;
223  
224 4 my $colinfos = $source->columns_info($cols);
225 my @text = map {
226 4 ▶ $self->_is_binary_data_type( $colinfos->{ $cols->[$_] }{data_type} ) ? 0 : 1
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_binary_data_type($$colinfos{$cols->[$_]}{'data_type'}) ? : 2 4 6
227 } 0 .. $#$cols;
228  
229 4 my $found = 0;
230 my @rows = map {
231 4 my @row = @$_;
232  
233 7 for my $i (0 .. $#row) {
234 0 ▶ if (ref $row[$i] eq 'REF' and ref ${ $row[$i] } eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $row[$i] eq 'REF' and ref ${$row[$i];} eq 'ARRAY') { } 0 11 11
elsif ($text[$i]) { } 7 4 11
Condition33%1/3
ref $row[$i] eq "REF" and ref ${$row[$i];} eq "ARRAY"
!ll&&!rl&&r
1100
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"
ABresult
0X0
100
111
235 0 my ($sql, @bind) = @${ $row[$i] };
236 0 my $resolved = $self->_resolve_bindattrs($source, \@bind, $colinfos);
237 0 my $as_characters = $self->_text_binds_as_characters(
238 $self->_get_dbh, $resolved,
239 );
240 0 ▶ if ($as_characters != $resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_characters != $resolved) 0 0 0
241 0 $found = 1;
242 0 $row[$i] = \[ $sql, @$as_characters ];
243 }
244 }
245 elsif ($text[$i]) {
246 7 my $characters = _beyond_ascii_as_characters($row[$i]);
247 7 ▶ next unless defined $characters;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $characters 5 2 7
248  
249 2 ▶ $self->_refuse_client_charset("a value for the column '$cols->[$i]'")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_client_charset_is_utf8($self->_get_dbh) 1 1 2
250 unless $self->_client_charset_is_utf8( $self->_get_dbh );
251  
252 1 $found = 1;
253 1 $row[$i] = $characters;
254 }
255 }
256  
257 6 \@row;
258 } @$data;
259  
260 3 ▶ return $found ? \@rows : $data;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 1 2 3
261 }
262  
263 # The bind values of a statement, those of a binary column as their bytes;
264 # the list itself when there is none. Throws for a character above 255.
265 17 ▶sub _binary_binds_as_bytes {
Subroutine _binary_binds_as_bytes: called CC=7 SCAR=19.9
266 17 my ($self, $bind) = @_;
267  
268 return $bind unless grep {
269 ref $_->[0] eq 'HASH' and $self->_is_binary_data_type( $_->[0]{sqlt_datatype} )
270 17 ▶ } @{ $bind || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {ref $_->[0] eq "HASH" and $self->_is_binary_data_type($_->[0]{"sqlt_datatype"});} @{$bind or [];} 11 6 17
Condition60%3/5
ref $_->[0] eq 'HASH' && $self->_is_binary_data_type($_->[0]{'sqlt_datatype'})
!ll&&!rl&&r
0186
$bind || []
l!l
170
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'})
ABresult
0X0
100
111
Truth table50%1/2
A
A= $bind
Aresult
11
00
271  
272 return [ map {
273 6 ( ref $_->[0] eq 'HASH'
274 and $self->_is_binary_data_type( $_->[0]{sqlt_datatype} )
275 and ref $_->[1] ne 'SCALAR' ) # bind_inout
276 7 ▶ ? [ $_->[0], $self->_binary_value_bytes( $_->[1], $_->[0]{dbic_colname} ) ]
Branch: 1 branch
BranchTrueFalseTotal
ref $_->[0] eq 'HASH' && $self->_is_binary_data_type($_->[0]{'sqlt_datatype'}) && ref $_->[1] ne 'SCALAR' ? : 6 1 7
Condition66%4/6
ref $_->[0] eq "HASH" and $self->_is_binary_data_type($_->[0]{"sqlt_datatype"}) and ref $_->[1] ne "SCALAR"
!ll&&!rl&&r
106
ref $_->[0] eq "HASH" and $self->_is_binary_data_type($_->[0]{"sqlt_datatype"})
!ll&&!rl&&r
016
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"
ABCresult
0XX0
10X0
1100
1111
277 : $_
278 } @$bind ];
279 }
280  
281 # ADR 0040, karr k71. Measured live 2026-10-19 (MSSQL 2022, DBD::ODBC 1.61 /
282 # tdsodbc 1.3.17): the base class's three round-trips do not give a plan over
283 # DBD::ODBC. The prepared SET SHOWPLAN_ALL ON does not outlive its prepare, so
284 # the explained query RUNS and its own rows come back as the "plan" -- well
285 # formed, no error, wrong. A silently wrong answer is refused. DBD::Sybase
286 # without placeholders returns the 18-column plan (base class, unchanged).
287 1 ▶sub _explain_query {
Subroutine _explain_query: called CC=1 SCAR=0.0
288 1 my ($self) = @_;
289  
290 1 DBIO::Exception->throw(
291 'DBIO::MSSQL: explain is refused over DBD::ODBC: no plan over ODBC. SQL Server\'s '
292 . 'SET SHOWPLAN_ALL does not take effect over a prepared statement there, '
293 . 'so the query would run and its own rows would be returned as the plan. '
294 . 'Connect through DBD::Sybase without placeholders for a plan '
295 . '(DBIO::MSSQL::Storage::Sybase), or read it in SQL Server Management '
296 . 'Studio.'
297 );
298 }
299  
300 # Ahead of the trace and the prepare (core's _dbh_execute, _dbh_prepare), so
301 # that a value that is no binary value is refused before anything is sent.
302 20 ▶sub _dbh_execute {
Subroutine _dbh_execute: called CC=1 SCAR=0.0
303 20 my ($self, $dbh, $sql, $bind, @rest) = @_;
304  
305 20 return $self->next::method(
306 $dbh, $sql,
307 $self->_binary_binds_as_bytes( $self->_text_binds_as_characters($dbh, $bind) ),
308 @rest,
309 );
310 }
311  
312 0 ▶sub _dbh_prepare {
Subroutine _dbh_prepare: not called CC=1 SCAR=6.9
313 0 my ($self, $dbh, $sql, $bind, @rest) = @_;
314  
315 0 return $self->next::method(
316 $dbh, $sql,
317 $self->_binary_binds_as_bytes( $self->_text_binds_as_characters($dbh, $bind) ),
318 @rest,
319 );
320 }
321  
322 4 ▶sub _insert_bulk {
Subroutine _insert_bulk: called CC=1 SCAR=0.0
323 4 my ($self, $source, $cols, $data) = @_;
324  
325 4 $data = $self->_text_rows_as_characters($source, $cols, $data);
326  
327 3 my ($as_bytes) = $self->_bulk_binary_values_as_bytes($source, $cols, $data);
328  
329 2 return $self->next::method($source, $cols, $as_bytes);
330 }
331  
332  
333  
334 15 1;
335  
336 __END__
« MSSQL/Util.pm ↑ Summary MSSQL/Storage/Sybase.pm »