Sybase/Storage/ASE.pm

filter: Statementstmt 89.2% 274 / 307 Branchbran 73.4% 94 / 128 Conditioncond 62.9% 68 / 108 MC/DCmcdc 44.8% 26 / 58 Subroutinesub 88.2% 45 / 51 Podpod 100% 7 / 7 totaltotal 78.0% 514 / 659 CC 145 SCAR 22.4
CC
145
Cov
80%
__ANON__
56.0
_mask_error_values
20.0
insert
19.9
CRAP 9.4
« Sybase/Introspect/Columns.pm ↑ Summary Sybase/Deploy.pm »
1 package DBIO::Sybase::Storage::ASE;
2 # ABSTRACT: Sybase ASE SQL Server support for DBIO
3  
4 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 our $VERSION = '0.900007';
8  
9 # The ASE::* trait classes below are standalone (no parent) and override
10 # methods that also exist in the deep DBIO::Storage::DBI hierarchy reached
11 # via DBIO::Sybase::Storage (e.g. last_insert_id, _execute, _insert_bulk,
12 # _exec_txn_begin). They MUST be listed before DBIO::Sybase::Storage so the
13 # C3 linearisation places them ahead of DBIO::Storage::DBI; otherwise their
14 # overrides are shadowed by core and never run (the trait methods chain into
15 # core via next::method).
16 34 ▶use base qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
17 DBIO::Sybase::Storage::ASE::LOBWriter
18 DBIO::Sybase::Storage::ASE::BulkInsert
19 DBIO::Sybase::Storage::ASE::IdentityRetrieval
20 DBIO::Sybase::Storage::ASE::TxnManager
21 DBIO::Sybase::Storage
22 DBIO::Storage::DBI::AutoCast
23 DBIO::Storage::DBI::IdentityInsert
24 34 /;
25 34 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 34 ▶use DBIO::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 34 ▶use Scalar::Util qw/blessed weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 34 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 34 ▶use Sub::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 34 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 34 ▶use Scope::Guard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 34 ▶use Context::Preserve 'preserve_context';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 34 ▶use DBIO::Util 'sigwarn_silencer';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 34 ▶use DBIO::Sybase::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 34 ▶use version ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 34 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38  
39 34 __PACKAGE__->sql_maker_class('DBIO::Sybase::SQLMaker');
40 34 __PACKAGE__->sql_quote_char ([qw/[ ]/]);
41 34 __PACKAGE__->datetime_parser_type(
42 'DBIO::Sybase::Storage::ASE::DateTime::Format'
43 );
44  
45 34 __PACKAGE__->mk_group_accessors('simple' =>
46 qw/_identity _identity_method _blob_log_on_update _parent_storage
47 _writer_storage _is_writer_storage
48 _bulk_storage _is_bulk_storage _began_bulk_work
49 /
50 );
51  
52 # ADR 0037. The base rendering of DBIO::Storage::DBI::_exists_value_sql --
53 #
54 # SELECT CASE WHEN EXISTS <inner> THEN 1 ELSE 0 END
55 #
56 # -- is grammatical Transact-SQL on ASE exactly as core writes it, so this
57 # driver declares the capability and deliberately does NOT override the hook.
58 # The declaration means somebody read the grammar, so here is what was read
59 # (SAP ASE 16.0 SP04 manuals), in the three places the fragment could break:
60 #
61 # * no FROM. Reference Manual: Commands, "select": the production is
62 # "select [all | distinct] [top <n>] <select_list> [<into_clause>]
63 # [<partition_clause>] [<from_clause>] ..." -- <from_clause> is optional,
64 # so ASE needs none of the dummy tables Oracle (DUAL), DB2
65 # (SYSIBM.SYSDUMMY1) and Firebird (RDB$DATABASE) do. The manual writes
66 # FROM-less selects itself, e.g. "select 1 intersect (select 2 intersect
67 # select 3)" under "Using intersect and except".
68 # * CASE in the select list. Reference Manual: Building Blocks, 3.15 "case":
69 # "can be used anywhere a value expression can be used", searched form
70 # "case when <search_condition> then <expression> [...] [else
71 # <expression>] end".
72 # * EXISTS as that <search_condition>. Reference Manual: Commands lists
73 # "where [not] exists (<subquery>)" among the search conditions, and the
74 # case entry defines its <search_condition> as "similar to the search
75 # conditions in a where clause". What ASE documents nowhere is EXISTS as a
76 # *value* expression -- the bare "SELECT EXISTS (...)" core emitted before
77 # ADR 0037 is a PostgreSQL-ism with no ASE grammar behind it.
78 #
79 # Declared here and not on DBIO::Sybase::Storage on purpose: that class is the
80 # base shared with DBIO::MSSQL::Storage::Sybase, which
81 # talks DBD::Sybase to Microsoft SQL Server. See the note above
82 # _set_operation_keyword below.
83 34 __PACKAGE__->_use_supports_exists_query(1);
84  
85 # F02 / F10 -- transactional DDL. Answered 0, but NOT for the reason the
86 # family's shared prose gives for this engine: ASE does not force an implicit
87 # COMMIT on DDL the way Oracle and MySQL do. It refuses the statement.
88 #
89 # Whether a create table may sit inside a transaction at all is a per-DATABASE
90 # server option, off by default (SAP ASE 16.1, Transact-SQL Users Guide,
91 # document version 1.0 / 2026-03-30, 23.3.1 "Allow Data Definition Commands in
92 # Transactions"): "You can use certain data definition language commands, such
93 # as create table, grant, and alter table, in transactions by setting the ddl
94 # in tran database option to true", set with sp_dboption <db>,"ddl in tran",
95 # true followed by checkpoint, from master, by a system administrator or the
96 # database owner only. A database created while model had it false has it
97 # false. With it false the statement does not half-commit -- the server
98 # rejects it, naming the database it rejected it in (msg 2762, "The '%s'
99 # command is not allowed within a multi-statement transaction in the '%.*s'
100 # database"). The same manual states the rule in passing for another command:
101 # "you cannot issue alter precomputed result set as part of a multistatement
102 # transaction (unless you set the ddl in tran option to true for the
103 # database)". t/22-ase-bulk-freetds.t records the same shape of refusal from
104 # another corner of the engine -- msg 226, "BULK INSERT not allowed within
105 # multi-statement transaction".
106 #
107 # That inverts the usual cost of getting this capability wrong, and is why it
108 # is worth declaring rather than inheriting. On an implicit-COMMIT engine a
109 # mistaken 1 buys nothing and loses nothing: txn_do brackets a loop that
110 # commits anyway. Here a mistaken 1 makes DBIO::Deploy::Base::_execute_ddl
111 # open a transaction (our txn_do -> begin_work -> CHAINED, see TxnManager)
112 # around DDL the server will then throw out, turning a working
113 # statement-at-a-time apply into a hard failure -- on the DEFAULT
114 # configuration of every ASE. So the 0 is not the conservative shrug core's
115 # default would be; it is the only answer that is true on every server this
116 # driver can be pointed at.
117 #
118 # The honest answer is "it depends on the server", and that is precisely what
119 # a capability cannot say. This one is a class-level fact, fixed before any
120 # connection, and DBIO::Deploy::Base reads it once per batch. A runtime probe
121 # is expressible in principle -- _determine_supports_transactional_ddl runs on
122 # a connected instance and could read ddl in tran out of sp_helpdb -- and is
123 # still not wanted: the answer is cached per $dbh while the deploy path spans
124 # two databases with independent settings (the live one and the temp one
125 # DBIO::Sybase::Deploy creates, whose setting comes from model), and it would
126 # make bracketing depend on server configuration nobody deploying this driver
127 # was asked about. SAP's own advice runs the same way: "Use data definition
128 # commands with caution. The only scenario in which using data definition
129 # language commands inside transactions is justified is in create schema."
130 #
131 # Two things this reasoning does NOT rest on, so that nobody re-derives them
132 # as support:
133 # * The CREATE DATABASE / DROP DATABASE of the temp-database deploy path
134 # (ADR 0005) are in the manual's always-forbidden list, banned even with
135 # ddl in tran true -- but they never reach _execute_ddl. Deploy's
136 # _create_temp_db / _drop_temp_db call $dbh->do directly and
137 # need a handle with AutoCommit for exactly that reason (they refuse one
138 # without, karr k96), independent of this capability.
139 # Nor does the DDL deployed INTO the temp database reach a bracket: core
140 # skips it because the handle belongs to no storage.
141 # * The diff emits no select into and no truncate table, the other two
142 # entries of that list a schema tool might plausibly produce.
143 # What the live apply path does emit -- create table, drop table, create
144 # index, drop index, alter table add/modify/replace/drop, alter table add/drop
145 # constraint -- sits in the manual's ddl-in-tran list, except that alter table
146 # appears in its prose and not in its enumeration, while the only alter table
147 # forms it forbids outright are ...partition and ...unpartition. That gap is
148 # the source's, not ours, and it is one more thing a 1 would have to bet on.
149 #
150 # Read, not measured: all of the above comes from the manual and from SAP's
151 # message texts. This repo's offline suite never touches a server and no live
152 # run was made to watch msg 2762 arrive, so treat the error numbers as
153 # citations rather than as something observed here.
154 #
155 # Declared here and not on DBIO::Sybase::Storage for the reason spelled out
156 # above _use_supports_exists_query, which bites harder here: that base
157 # is first in the C3 linearisation of DBIO::MSSQL::Storage::Sybase, ahead of
158 # DBIO::MSSQL::Storage, so a 0 on it would both state something false about
159 # Microsoft SQL Server (whose DDL is transactional) and pre-empt dbio-mssql's
160 # own declaration if it ever makes one. The base stays silent; value,
161 # declaredness and that silence are pinned by t/42-deploy-transactional-ddl.t.
162 34 __PACKAGE__->_use_transactional_ddl(0);
163  
164 # ADR 0039 -- does this deployment's ASE have intersect and except at all?
165 #
166 # Unlike every other gap in this family the ASE version boundary runs the
167 # other way round: the operators are NEW (16.0 SP03, 2019), so the servers
168 # that lack them are the OLD ones. dbio-oracle's equivalent flag defaults to 0
169 # because MINUS ALL exists only on 21c and refusing protects the majority;
170 # here a default of 0 would take intersect and except away from every server
171 # SAP still supports in order to protect legacy installs, which is the
172 # regression ADR 0039 section 3 lists as a reason against gating at all. So
173 # this is section 7 option (b) with the polarity the engine fact dictates: an
174 # opt-OUT a deployment sets when it knows its server predates 16.0 SP03 (or is
175 # a Cluster Edition, which SAP note 2687392 reports as lacking them in every
176 # version). Declared outright on both tiers, exactly like dbio-oracle's, so
177 # that the hook stays a static class fact: the only honest _determine_supports_*
178 # here would read the server version, and this is the spot a future author
179 # would be tempted to add that probe.
180 34 __PACKAGE__->mk_group_accessors( dbms_capability => '_supports_intersect_except' );
181 34 __PACKAGE__->mk_group_accessors( use_dbms_capability => '_use_intersect_except' );
182 34 __PACKAGE__->_use_intersect_except (1);
183 0 ▶sub _determine_supports_intersect_except { 1 }
Subroutine _determine_supports_intersect_except: not called CC=1 SCAR=6.9
184  
185 # ADR 0039 -- the keyword the six DBIO::ResultSet set operations join their
186 # operands with, and the seam that refuses the ones ASE does not have.
187 #
188 # The engine facts, read rather than assumed (SAP ASE 16.0 SP04 Reference
189 # Manual: Commands unless noted):
190 #
191 # * union has an ALL form. The "union operator" entry gives
192 # "union [all]" with all as a documented parameter: "includes all rows in
193 # the results; duplicates are not removed".
194 # * intersect and except do NOT. "Using intersect and except" gives both
195 # productions with no all anywhere in them, describes intersect as
196 # "Duplicate rows are eliminated from the result set", and its own worked
197 # example subtracts t2 = (1,6,6,6,7,7,7,7) from t1 = (2,6,1,1) and returns
198 # the single row 2 -- the duplicate 1s collapse, so there is no ALL
199 # semantics to reach. The strings "except all", "intersect all" and
200 # "minus all" do not occur anywhere in that manual.
201 # * except is spelled except. ASE takes minus as an interchangeable synonym
202 # ("the parameter name except is used throughout the documentation for the
203 # sake of simplicity"), so core's ANSI base map already answers correctly
204 # and this driver has no spelling to contribute -- only refusals.
205 # * intersect and except are NEW in 16.0 SP03: SAP ASE 16.0 SP03 What's New,
206 # chapter 15 "Version 16.0 SP03", section 15.5.1 "intersect and except
207 # Parameters". SAP note 2687392 ("Error 156 when trying to use EXCEPT /
208 # MINUS set operator - ASE") gives the other side of the boundary: "all
209 # versions prior to 16.0 SP03", plus ASE Cluster Edition in all versions.
210 #
211 # Hence two different kinds of refusal in one hook. except_all / intersect_all
212 # are refused UNCONDITIONALLY because the fact is unconditional -- no ASE has
213 # ever had them, so nothing is being withheld from a version that works.
214 # except / intersect are refused only where the class fact above says this
215 # server is too old, because on 16.0 SP03 and newer they work and taking them
216 # away would be the section 7 cost with none of the section 7 benefit.
217 #
218 # Static class fact throughout, with no version probe: ResultSet's
219 # _set_operation bakes the keyword into a literal from clause at construction
220 # time, so a runtime-resolved keyword is not expressible -- and asking the
221 # server which word it wants is exactly the connection-at-query-build-time
222 # this hook's predecessor removed.
223 #
224 # Lives on ::ASE and not on DBIO::Sybase::Storage for the reason spelled out
225 # above _use_supports_exists_query: the base is shared with
226 # DBIO::MSSQL::Storage::Sybase, which linearises it AHEAD of
227 # DBIO::MSSQL::Storage under c3, so an override there would shadow the MSSQL
228 # refusal with an ASE answer about Microsoft SQL Server.
229 29 ▶sub _set_operation_keyword {
Subroutine _set_operation_keyword: called CC=7 SCAR=19.5
230 29 my ($self, $op) = @_;
231  
232 29 ▶ return $self->next::method($op) unless defined $op;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op 1 28 29
233  
234 28 ▶ if ($op eq 'except_all' or $op eq 'intersect_all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "except_all" or $op eq "intersect_all") 11 17 28
Condition100%3/3
$op eq "except_all" or $op eq "intersect_all"
l!l&&r!l&&!r
7417
MC/DC100%2/2
$op eq "except_all" or $op eq "intersect_all"
$op eq "except_all" $op eq "intersect_all"
Truth table100%3/3
A or B
A= $op eq "except_all"B= $op eq "intersect_all"
ABresult
1X1
011
000
235 11 (my $distinct_form = $op) =~ s/_all\z//;
236  
237 11 $self->throw_exception(
238 "Sybase ASE has no $op: its intersect and except operators always "
239 . 'return distinct rows and take no ALL, while union on the same engine '
240 . 'is documented as "union [all]". This refusal is unconditional and is '
241 . 'not a version compromise -- ASE gained intersect and except in 16.0 '
242 . 'SP03 and neither has ever had an ALL form; "except all", "intersect '
243 . 'all" and "minus all" occur nowhere in the SAP ASE 16.0 SP04 Reference '
244 . 'Manual: Commands. The nearest available operation is '
245 . "->$distinct_form(), but it is not a substitute: it collapses duplicate "
246 . 'rows, so it answers a different question.'
247 );
248 }
249  
250 17 ▶ if ($op eq 'except' or $op eq 'intersect') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "except" or $op eq "intersect") 10 7 17
Condition100%3/3
$op eq "except" or $op eq "intersect"
l!l&&r!l&&!r
647
MC/DC100%2/2
$op eq "except" or $op eq "intersect"
$op eq "except" $op eq "intersect"
Truth table100%3/3
A or B
A= $op eq "except"B= $op eq "intersect"
ABresult
1X1
011
000
251 10 ▶ $self->throw_exception(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_use_intersect_except 4 6 10
252 "Sybase ASE gained $op only in version 16.0 SP03; older releases answer "
253 . 'it with "Incorrect syntax near the keyword" (SAP note 2687392, which '
254 . 'also reports ASE Cluster Edition as lacking it in every version). This '
255 . 'deployment has declared its server one of those, with '
256 . 'DBIO::Sybase::Storage::ASE->_use_intersect_except(0), so the operation '
257 . 'is refused while the query is built rather than by the server. On 16.0 '
258 . 'SP03 or newer, drop that declaration -- it defaults to 1. The hook '
259 . 'cannot decide this for you: DBIO::ResultSet::_set_operation bakes the '
260 . 'keyword into the query at construction time, so probing the server '
261 . 'version here would open a connection during query build, purely in '
262 . 'order to throw (ADR 0039 section 7).'
263 ) unless $self->_use_intersect_except;
264 }
265  
266 # union, union all -- and intersect / except once the server is new enough.
267 # ASE spells all four the ANSI way, so the base map answers and an unknown
268 # $op lands on core's throw there rather than being invented here.
269 13 return $self->next::method($op);
270 }
271  
272 # karr k28 -- the function DBIO::ResultSet::rand drops into an order_by
273 # literal. Core answers RANDOM(), which ASE simply does not have: the SAP ASE
274 # 16.0 "Transact-SQL Functions" list carries rand and newid and no random at
275 # all, so the inherited default dies naming the function the server could not
276 # find.
277 #
278 # The obvious replacement is the WRONG one, and that is this ticket's finding.
279 # rand() exists, but it is not computed per row -- the reference entry for its
280 # sibling rand2 defines itself by exactly that contrast, "Unlike rand, it is
281 # computed for each returned row when it is used in the select list", with the
282 # worked example "If there are n rows in table t, the following select
283 # statement returns n different random values, not just one: select rand2()
284 # from t". So ORDER BY rand() hands every row the SAME sort key: the ordering
285 # is not random, and nothing says so. That is a silent wrong answer, strictly
286 # worse than the loud RANDOM() it would replace. rand2() has the per-row
287 # behaviour and is documented out of this position instead -- "The behavior of
288 # rand2 in places other than the select list is currently undefined" -- and an
289 # order_by is such a place.
290 #
291 # newid() is the one whose own entry carries the per-row guarantee: "By
292 # default newid returns new values for every filtered row." It yields a
293 # 32-byte human-readable GUID (varchar, no dashes) by default, so ordering by
294 # it shuffles.
295 #
296 # That DBIO::MSSQL::Storage answers NEWID() too is a coincidence of two
297 # independently documented engine facts, not shared Transact-SQL heritage, and
298 # it does NOT license moving this declaration up a level. It lives on ::ASE
299 # for the reason spelled out above _use_supports_exists_query: the shared
300 # shared base DBIO::Sybase::Storage is linearised AHEAD of
301 # DBIO::MSSQL::Storage by DBIO::MSSQL::Storage::Sybase under c3, so a
302 # declaration there would answer for Microsoft SQL Server out of this
303 # distribution. dbio-mssql's t/56-explain-query.t asserts that from its side.
304 8 ▶sub _random_function { 'NEWID()' }
Subroutine _random_function: called CC=1 SCAR=0.0
305  
306 # karr k28 / ADR 0040 section 7: ASE emits its plan as server MESSAGES, not as
307 # a rowset -- the channel DBD::Sybase exposes only through syb_err_handler --
308 # so _explain_query collects them through the _execute_sth seam core karr k140
309 # built. Both overrides live HERE, on ::ASE, and not on DBIO::Sybase::Storage:
310 # ASE spells the setting "set showplan on" where Microsoft SQL Server spells it
311 # SET SHOWPLAN_ALL ON, so a declaration on the shared base would break
312 # dbio-mssql's DBD::Sybase path.
313 #
314 # The handler is installed on the handle the statement runs on -- the one
315 # _dbh_execute received, never $self->dbh -- so tracing/redact_bind_value
316 # (ADR 0025), dbh_do retry and the read handler of a replicated storage all
317 # survive. It fires only for the showplan message numbers (3612-3615, 6201-6299,
318 # 10201-10299, per DBD::Sybase's own worked example) and returns 0 for them --
319 # showplan output is not an error. Everything else is chained to the handler
320 # the borrow displaced: the slot is taken for the duration of the statement,
321 # but a caller's own syb_err_handler (PRINT/dbcc output processing) must keep
322 # seeing its messages and keep its verdict while the borrow lasts -- (karr k34;
323 # the restore pattern is core karr k153 / ADR 0040 section 7). The restore is a
324 # Scope::Guard: if execute throws, the handler must not outlive the statement it
325 # was installed for, or a caller's own syb_err_handler would be lost and a stale
326 # closure left on the handle.
327 260 ▶sub _execute_sth {
Subroutine _execute_sth: called CC=1 SCAR=0.5
328 260 my ($self, $dbh, $sth) = @_;
329  
330 260 my @messages;
331 260 my $old = $dbh->{syb_err_handler};
332 16 ▶ $dbh->{syb_err_handler} = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
333 16 my ($err, $sev, $state, $line, $server, $proc, $msg) = @_;
334 16 ▶ if ($err >= 3612 && $err <= 3615
Branch: 1 branch
BranchTrueFalseTotal
if ($err >= 3612 and $err <= 3615 or $err >= 6201 and $err <= 6299 or $err >= 10201 and $err <= 10299) 6 10 16
Condition100%15/15
$err >= 3612 and $err <= 3615 or $err >= 6201 and $err <= 6299 or $err >= 10201 and $err <= 10299
l!l&&r!l&&!r
4210
$err >= 3612 and $err <= 3615 or $err >= 6201 and $err <= 6299
l!l&&r!l&&!r
2212
$err >= 3612 and $err <= 3615
!ll&&!rl&&r
1132
$err >= 6201 and $err <= 6299
!ll&&!rl&&r
572
$err >= 10201 and $err <= 10299
!ll&&!rl&&r
732
MC/DC100%6/6
$err >= 3612 and $err <= 3615 or $err >= 6201 and $err <= 6299 or $err >= 10201 and $err <= 10299
$err >= 3612 $err <= 3615 $err >= 6201 $err <= 6299 $err >= 10201 $err <= 10299
Truth table46%7/15
A and B or C and D or E and F
A= $err >= 3612B= $err <= 3615C= $err >= 6201D= $err <= 6299E= $err >= 10201F= $err <= 10299
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
335 || $err >= 6201 && $err <= 6299
336 || $err >= 10201 && $err <= 10299) {
337 6 push @messages, $msg;
338 6 return 0; # showplan output is not an error
339 }
340 10 ▶ return $old ? $old->(@_) : 1; # everything else: the prior handler's verdict
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 9 1 10
341 260 };
342 260 ▶ my $restore = Scope::Guard->new(sub { $dbh->{syb_err_handler} = $old });
Subroutine __ANON__: called CC=1 SCAR=0.0
343  
344 # The client library tells a conversion it could not do with a warn(), not
345 # an error (cs_convert failed (to_money(x))), and the text holds the value.
346 # The warning goes on to the handler it displaced, with the value masked;
347 # every other warning passes unchanged.
348 260 my $previous = $SIG{__WARN__};
349 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
350 0 my $text = $_[0];
351 0 ▶ if (defined $text and !ref $text and $text =~ /\bcs_convert failed \(/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text and not ref $text and $text =~ /\bcs_convert failed \(/) 0 0 0
Condition0%0/6
defined $text and not ref $text and $text =~ /\bcs_convert failed \(/
!ll&&!rl&&r
000
defined $text and not ref $text
!ll&&!rl&&r
000
MC/DC0%0/3
defined $text and not ref $text and $text =~ /\bcs_convert failed \(/
defined $text not ref $text $text =~ /\bcs_convert failed \(/
Truth table0%0/4
A and not(B) and C
A= defined $textB= not ref $textC= $text =~ /\bcs_convert failed \(/
ABCresult
0XX0
10X0
1100
1111
352 0 ▶ my $values = eval { $self->_warned_values($sth) } || [];
Condition0%0/2
eval { do { $self->_warned_values($sth) } } || []
l!l
00
MC/DC0%0/1
eval { do { $self->_warned_values($sth) } } || []
eval { do { $self->_warned_values($sth) } }
Truth table0%0/2
A
A= eval { do { $self->_warned_values($sth) } }
Aresult
11
00
353 0 ▶ my $tail = $text =~ s/(\s+at \S+ line \d+\.?\n?)\z// ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/(\s+at \S+ line \d+\.?\n?)\z// ? : 0 0 0
354 0 $text = $self->_mask_error_values($text, $values) . $tail;
355 }
356 0 ▶ ref $previous eq 'CODE' ? $previous->($text, @_[1..$#_]) : warn $text;
Branch: 1 branch
BranchTrueFalseTotal
ref $previous eq 'CODE' ? : 0 0 0
357 260 };
358  
359 260 my $rv = $sth->execute;
360  
361 258 return ($rv, \@messages);
362 }
363  
364 # The plain values bound to a running statement, as the handle knows them.
365 0 ▶sub _warned_values {
Subroutine _warned_values: not called CC=3 SCAR=24.8
366 0 my ($self, $sth) = @_;
367 0 my $params = $sth->{ParamValues};
368 0 ▶ return [] unless ref $params eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params eq "HASH" 0 0 0
369 0 ▶ return [ grep { defined and !ref } values %$params ];
Condition0%0/3
defined $_ && !ref($_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
370 }
371  
372  
373 0 ▶sub _mask_error_values {
Subroutine _mask_error_values: not called CC=4 SCAR=30.0
374 0 my ($self, $text, $values, $statement) = @_;
375  
376 0 ▶ return $text unless defined $text and !ref $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and not ref $text 0 0 0
Condition0%0/3
defined $text and not ref $text
!ll&&!rl&&r
000
MC/DC0%0/2
defined $text and not ref $text
defined $text not ref $text
Truth table0%0/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
377  
378 0 my $masked = eval { DBIO::Sybase::Util::mask_error_details($text, $values) };
379 0 ▶ return $self->next::method(defined $masked ? $masked : $text, $values, $statement);
Branch: 1 branch
BranchTrueFalseTotal
defined $masked ? : 0 0 0
380 }
381  
382 # The whole operation of obtaining a plan, per SAP "Using set showplan with
383 # noexec": the plain form prints the plan AND runs the query, so noexec has to
384 # bracket it -- five statements in all. The plan arrives as server messages,
385 # read back from _server_messages right after the query statement (each execute
386 # overwrites it with that statement's own messages), and wrapped as a
387 # single-column rowset -- the shape _explain_query's contract names. The two
388 # OFF statements run from a Scope::Guard, created only after both ONs
389 # succeeded: if the query throws, an unguarded OFF is skipped and the session
390 # is left with showplan on -- every later query on that connection returns a
391 # plan instead of its rows, and with noexec still on, does not even run.
392 4 ▶sub _explain_query {
Subroutine _explain_query: called CC=1 SCAR=0.0
393 4 my ($self, $sql, $bind) = @_;
394  
395 4 $self->_execute_rendered('set showplan on', []);
396 3 $self->_execute_rendered('set noexec on', []);
397  
398 3 ▶ my $restore = Scope::Guard->new(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
399 3 $self->_execute_rendered('set noexec off', []);
400 3 $self->_execute_rendered('set showplan off', []);
401 3 });
402  
403 3 $self->_execute_rendered($sql, $bind);
404 2 my $messages = $self->_server_messages;
405  
406 2 return [ map { [ $_ ] } @$messages ];
407 }
408  
409  
410 34 my @also_proxy_to_extra_storages = qw/
411 connect_call_set_auto_cast auto_cast connect_call_blob_setup
412 connect_call_datetime_setup
413  
414 disconnect _connect_info _sql_maker _sql_maker_opts disable_sth_caching
415 auto_savepoint unsafe cursor_class debug debugobj schema
416 /;
417  
418  
419 # The one decision this class takes about itself, for a declared storage and a
420 # storage pinned to this class (DBIO::Sybase::Storage::_adapt_to_access_path).
421 # It asks the client library, through the handle, and is taken once: a storage
422 # that is the NoBindVars class has been through it.
423 87 ▶sub _adapt_to_placeholder_support {
Subroutine _adapt_to_placeholder_support: called CC=8 SCAR=20.8
424 87 my $self = shift;
425  
426 87 my $no_bind_vars = __PACKAGE__ . '::NoBindVars';
427  
428 87 ▶ return if $self->isa($no_bind_vars);
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa($no_bind_vars) 0 87 87
429  
430 87 ▶ if ($self->_using_freetds) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_using_freetds) { } 27 60 87
elsif (not $self->_get_dbh->{'syb_dynamic_supported'}) { } 13 47 60
elsif (not $self->_use_typeless_placeholders) { } 7 40 47
431 27 ▶ carp_once <<'EOF' unless $ENV{DBIO_SYBASE_FREETDS_NOWARN};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"DBIO_SYBASE_FREETDS_NOWARN"} 0 27 27
432  
433 You are using FreeTDS with Sybase.
434  
435 We will do our best to support this configuration, but please consider this
436 support experimental.
437  
438 TEXT/IMAGE columns will definitely not work.
439  
440 You are encouraged to recompile DBD::Sybase with the Sybase Open Client libraries
441 instead.
442  
443 See perldoc DBIO::Sybase::Storage::ASE for more details.
444  
445 To turn off this warning set the DBIO_SYBASE_FREETDS_NOWARN environment
446 variable.
447 EOF
448  
449 27 ▶ if (not $self->_use_typeless_placeholders) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_use_typeless_placeholders) 13 14 27
450 13 ▶ if ($self->_use_placeholders) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_use_placeholders) { } 6 7 13
451 6 $self->auto_cast(1);
452 }
453 else {
454 7 $self->ensure_class_loaded($no_bind_vars);
455 7 bless $self, $no_bind_vars;
456 }
457 }
458 }
459  
460 elsif (not $self->_get_dbh->{syb_dynamic_supported}) {
461 # not necessarily FreeTDS, but no placeholders nevertheless
462 13 $self->ensure_class_loaded($no_bind_vars);
463 13 bless $self, $no_bind_vars;
464 }
465 # this is highly unlikely, but we check just in case
466 elsif (not $self->_use_typeless_placeholders) {
467 7 $self->auto_cast(1);
468 }
469 }
470  
471 156 ▶sub _init {
Subroutine _init: called CC=7 SCAR=19.5
472 156 my $self = shift;
473  
474 156 $self->next::method(@_);
475  
476 156 ▶ if (my $ver = $self->_using_freetds && $self->_using_freetds_version) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ver = $self->_using_freetds && $self->_using_freetds_version) 45 111 156
Condition100%3/3
$self->_using_freetds && $self->_using_freetds_version
!ll&&!rl&&r
107445
MC/DC100%2/2
$self->_using_freetds && $self->_using_freetds_version
$self->_using_freetds $self->_using_freetds_version
Truth table100%3/3
A && B
A= $self->_using_freetdsB= $self->_using_freetds_version
ABresult
0X0
100
111
477 # Only the historic FreeTDS 0.8x line has the known statement-caching bug;
478 # parse as a dotted version so 1.x is not coerced to a number (and no
479 # "isn't numeric" warning is emitted).
480 45 ▶ if (version->parse("v$ver") <= version->parse('v0.82')) {
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("v$ver") <= "version"->parse("v0.82")) 0 45 45
481 0 carp_once(
482 "Buggy FreeTDS version $ver detected, statement caching will not work and "
483 . 'will be disabled.'
484 );
485 0 $self->disable_sth_caching(1);
486 }
487 }
488  
489 156 $self->_set_max_connect(256);
490  
491 # create storage for insert/(update blob) transactions,
492 # unless this is that storage
493 156 ▶ return if $self->_parent_storage;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_parent_storage 58 98 156
494  
495 98 my $writer_storage = (ref $self)->new;
496  
497 98 $writer_storage->_is_writer_storage(1); # just info
498 98 $writer_storage->connect_info($self->connect_info);
499 98 $writer_storage->auto_cast($self->auto_cast);
500  
501 98 weaken ($writer_storage->{_parent_storage} = $self);
502 98 $self->_writer_storage($writer_storage);
503  
504 # create a bulk storage unless connect_info is a coderef
505 98 ▶ return if ref($self->_dbi_connect_info->[0]) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->_dbi_connect_info->[0] eq "CODE" 1 97 98
506  
507 # FreeTDS' blk-library cannot do BCP ("Type '7' not implemented", and BULK
508 # INSERT is rejected inside the multi-statement txn DBD::Sybase keeps open).
509 # Without a bulk storage the _insert_bulk eligibility check falls back to
510 # regular array inserts, which is the only thing that works under FreeTDS.
511 97 ▶ return if $self->_using_freetds;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_using_freetds 31 66 97
512  
513 66 my $bulk_storage = (ref $self)->new;
514  
515 66 $bulk_storage->_is_bulk_storage(1); # for special ->disconnect acrobatics
516 66 $bulk_storage->connect_info($self->connect_info);
517  
518 # this is why
519 66 $bulk_storage->_dbi_connect_info->[0] .= ';bulkLogin=1';
520  
521 66 weaken ($bulk_storage->{_parent_storage} = $self);
522 66 $self->_bulk_storage($bulk_storage);
523 }
524  
525 34 for my $method (@also_proxy_to_extra_storages) {
526 34 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
527 34 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
528  
529 510 my $replaced = __PACKAGE__->can($method);
530  
531 510 ▶ *{$method} = Sub::Util::set_subname $method => sub {
Subroutine connect_call_blob_setup: called CC=4 SCAR=13.9
Subroutine _sql_maker: called CC=4 SCAR=13.9
Pod documented
Pod documented
532 62 my $self = shift;
533 # class invocant (e.g. core connect_info's ref($self)->cursor_class):
534 # there are no extra storages to proxy to (karr k45)
535 62 ▶ return $self->$replaced(@_) unless ref $self;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $self 2 60 62
unless ref $self 213 6910 7123
536 60 ▶ $self->_writer_storage->$replaced(@_) if $self->_writer_storage;
Branch: 2 branches
BranchTrueFalseTotal
if $self->_writer_storage 0 60 60
if $self->_writer_storage 980 5930 6910
537 60 ▶ $self->_bulk_storage->$replaced(@_) if $self->_bulk_storage;
Branch: 2 branches
BranchTrueFalseTotal
if $self->_bulk_storage 0 60 60
if $self->_bulk_storage 592 6318 6910
538 60 return $self->$replaced(@_);
539 510 };
540 }
541  
542 180 ▶sub disconnect {
Subroutine disconnect: called CC=3 SCAR=11.0
Pod documented
543 180 my $self = shift;
544  
545 # Even though we call $sth->finish for uses off the bulk API, there's still an
546 # "active statement" warning on disconnect, which we throw away here.
547 # This is due to the bug described in _insert_bulk.
548 # Currently a noop because 'prepare' is used instead of 'prepare_cached'.
549 180 ▶ local $SIG{__WARN__} = sigwarn_silencer(qr/active statement/i)
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_bulk_storage 14 166 180
550 if $self->_is_bulk_storage;
551  
552 # so that next transaction gets a dbh
553 180 ▶ $self->_began_bulk_work(0) if $self->_is_bulk_storage;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_bulk_storage 14 166 180
554  
555 180 $self->next::method;
556 }
557  
558 # This is only invoked for FreeTDS drivers by ::Storage::DBI::Sybase::FreeTDS
559 46 ▶sub _set_autocommit_stmt {
Subroutine _set_autocommit_stmt: called CC=2 SCAR=7.2
560 46 my ($self, $on) = @_;
561  
562 46 ▶ return 'SET CHAINED ' . ($on ? 'OFF' : 'ON');
Branch: 1 branch
BranchTrueFalseTotal
$on ? : 46 0 46
563 }
564  
565 # Set up session settings for Sybase databases for the connection.
566 #
567 # Make sure we have CHAINED mode turned on if AutoCommit is off in non-FreeTDS
568 # DBD::Sybase (since we don't know how DBD::Sybase was compiled.) If however
569 # we're using FreeTDS, CHAINED mode turns on an implicit transaction which we
570 # only want when AutoCommit is off.
571 165 ▶sub _run_connection_actions {
Subroutine _run_connection_actions: called CC=3 SCAR=11.0
572 165 my $self = shift;
573  
574 # ASE cuts a string that is too long without a word: a char(10) takes 11
575 # characters, varchar(5) turns 'abcdefgh' into 'abcde'. With this option the
576 # statement is refused instead (Msg 9502, "string data right truncated").
577 # Set on every connection, the first one, a reconnect, the writer storage's
578 # and the bulk storage's (karr k97, the maintainer's decision: silent cutting
579 # is never wanted). A change of behaviour for every user of the driver.
580 165 $self->_dbh->do('set string_rtruncation on');
581  
582 165 ▶ if ($self->_is_bulk_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_bulk_storage) 8 157 165
583 # this should be cleared on every reconnect
584 8 $self->_began_bulk_work(0);
585 8 return;
586 }
587  
588 157 ▶ $self->_dbh->{syb_chained_txn} = 1
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_using_freetds 111 46 157
589 unless $self->_using_freetds;
590  
591 157 $self->next::method(@_);
592 }
593  
594  
595 0 ▶sub connect_call_blob_setup {
Subroutine connect_call_blob_setup: not called CC=2 SCAR=17.9
Pod documented
596 0 my $self = shift;
597 0 my %args = @_;
598 0 my $dbh = $self->_dbh;
599 0 $dbh->{syb_binary_images} = 1;
600  
601 $self->_blob_log_on_update($args{log_on_update})
602 0 ▶ if exists $args{log_on_update};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"log_on_update"} 0 0 0
603 }
604  
605 1429 ▶sub _is_lob_column {
Subroutine _is_lob_column: called CC=1 SCAR=0.0
606 1429 my ($self, $source, $column) = @_;
607  
608 1429 return $self->_is_lob_type($source->column_info($column)->{data_type});
609 }
610  
611 # Over FreeTDS a string with a character beyond ASCII does not arrive in a
612 # character column: the client library cannot convert it to the character set
613 # of the server, says so AFTER the statement was executed (Open Client Msg 97
614 # / 98), and the row holds a blank where the value was (measured, FreeTDS
615 # 1.3.17, U+00FC, U+20AC and U+65E5, varchar and univarchar). So it is refused
616 # before anything is sent (karr k97), as dbio-mssql refuses it over
617 # DBD::Sybase (its karr k49). Not for NULL, not for a binary column (its bytes
618 # are no characters), and not where the client library is not FreeTDS: nothing
619 # was measured there. What is told is table and column, never the value.
620 34 our $BINARY_TYPE_RE = my $BINARY_TYPE = qr/\A(?:(?:var)?binary|image|blob|bytea|bit)\b/i;
621  
622 304 ▶sub _refuse_non_ascii_binds {
Subroutine _refuse_non_ascii_binds: called CC=15 SCAR=28.3
623 304 my ($self, $ident, $bind) = @_;
624 # the cheap test first: asking the client library needs a connection
625 299 ▶ return unless grep { defined $_->[1] and not ref $_->[1] and $_->[1] =~ /[^\x00-\x7F]/ }
Condition83%5/6
defined $_->[1] && !ref($_->[1]) && $_->[1] =~ /[^\x00-\x7F]/
!ll&&!rl&&r
228710
defined $_->[1] and not ref $_->[1]
!ll&&!rl&&r
20297
MC/DC66%2/3
defined $_->[1] && !ref($_->[1]) && $_->[1] =~ /[^\x00-\x7F]/
defined $_->[1] not ref $_->[1] $_->[1] =~ /[^\x00-\x7F]/
Truth table75%3/4
A and not(B) && C
A= defined $_->[1]B= not ref $_->[1]C= $_->[1] =~ /[^\x00-\x7F]/
ABCresult
0XX0
10X0
1100
1111
626 304 ▶ @{ $bind || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_->[1] and not ref $_->[1] and $_->[1] =~ /[^\x00-\x7F]/;} @{$bind or [];} 294 10 304
Condition50%1/2
$bind || []
l!l
3040
MC/DC0%0/1
$bind || []
$bind
Truth table50%1/2
A
A= $bind
Aresult
11
00
627 10 ▶ return unless $self->_using_freetds;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_using_freetds 2 8 10
628  
629 8 my $position = 0;
630 8 ▶ for my $item (@{ $bind || [] }) {
Condition50%1/2
$bind || []
l!l
80
MC/DC0%0/1
$bind || []
$bind
Truth table50%1/2
A
A= $bind
Aresult
11
00
631 14 $position++;
632 14 my ($attrs, $value) = @$item;
633 14 ▶ next unless defined $value and not ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 0 14 14
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
634 14 ▶ next unless $value =~ /[^\x00-\x7F]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /[^\x00-\x7F]/ 6 8 14
635 8 ▶ next if ref $attrs eq 'HASH' and ($attrs->{sqlt_datatype} // '') =~ $BINARY_TYPE;
Branch: 1 branch
BranchTrueFalseTotal
if ref $attrs eq "HASH" and ($attrs->{"sqlt_datatype"} // "") =~ /$BINARY_TYPE/ 2 6 8
Condition60%3/5
ref $attrs eq "HASH" and ($attrs->{"sqlt_datatype"} // "") =~ /$BINARY_TYPE/
!ll&&!rl&&r
062
$attrs->{"sqlt_datatype"} // ""
l!l
80
MC/DC0%0/2
ref $attrs eq "HASH" and ($attrs->{"sqlt_datatype"} // "") =~ /$BINARY_TYPE/
ref $attrs eq "HASH" $attrs->{"sqlt_datatype"}
Truth table33%1/3
A and B
A= ref $attrs eq "HASH"B= $attrs->{"sqlt_datatype"}
ABresult
0X0
100
111
636 $self->_throw_non_ascii(
637 $self->_table_name_of($ident),
638 ref $attrs eq 'HASH' ? $attrs->{dbic_colname} : undef,
639 6 ▶ $position,
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq 'HASH' ? : 6 0 6
640 );
641 }
642 }
643  
644 # The table a statement is about, for a message: a source's name, or the first
645 # table of a FROM (`[ { me => 'doc' } ]`); undef when it is neither.
646 8 ▶sub _table_name_of {
Subroutine _table_name_of: called CC=10 SCAR=29.1
647 8 my ($self, $ident) = @_;
648 8 ▶ if (blessed $ident and $ident->can('name')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ident) and $ident->can("name")) 6 2 8
Condition66%2/3
builtin::blessed($ident) and $ident->can("name")
!ll&&!rl&&r
206
MC/DC50%1/2
builtin::blessed($ident) and $ident->can("name")
builtin::blessed($ident) $ident->can("name")
Truth table66%2/3
A and B
A= builtin::blessed($ident)B= $ident->can("name")
ABresult
0X0
100
111
649 6 my $name = $ident->name;
650 6 ▶ return ref $name ? undef : $name;
Branch: 1 branch
BranchTrueFalseTotal
ref $name ? : 0 6 6
651 }
652 2 ▶ if (ref $ident eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ident eq "ARRAY") 2 0 2
653 2 my ($first) = @$ident;
654 2 ▶ $first = (first { blessed $_ } values %$first) // (values %$first)[0] if ref $first eq 'HASH';
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 1 branch
BranchTrueFalseTotal
if ref $first eq "HASH" 2 0 2
Condition33%1/3
&first(sub { builtin::blessed($_); } , values %$first) // (values %$first)[0]
l!l&&r!l&&!r
200
MC/DC0%0/2
&first(sub { builtin::blessed($_); } , values %$first) // (values %$first)[0]
&first(sub { builtin::blessed($_); } , values %$first) (values %$first)[0]
Truth table33%1/3
A // B
A= &first(sub { builtin::blessed($_); } , values %$first)B= (values %$first)[0]
ABresult
1X1
011
000
655 2 ▶ return $self->_table_name_of($first) if blessed $first;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($first) 2 0 2
656 0 ▶ return (defined $first and !ref $first) ? $first : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $first && !ref($first) ? : 0 0 0
Condition0%0/3
defined $first and not ref $first
!ll&&!rl&&r
000
MC/DC0%0/2
defined $first and not ref $first
defined $first not ref $first
Truth table0%0/3
A and not(B)
A= defined $firstB= not ref $first
ABresult
0X0
100
111
657 }
658 0 return undef;
659 }
660  
661 8 ▶sub _throw_non_ascii {
Subroutine _throw_non_ascii: called CC=4 SCAR=17.9
662 8 my ($self, $table, $column, $position) = @_;
663 8 ▶ DBIO::Exception->throw(sprintf
Branch: 1 branch
BranchTrueFalseTotal
defined $column ? : 8 0 8
Condition25%1/4
$table // "(statement)"
l!l
80
$table // "(statement)"
l!l
00
MC/DC0%0/1
$table // "(statement)"
$table
MC/DC0%0/1
$table // "(statement)"
$table
Truth table50%1/2
A
A= $table
Aresult
11
00
Truth table0%0/2
A
A= $table
Aresult
11
00
664 'DBIO::Sybase: %s has a character beyond ASCII and is refused: over FreeTDS '
665 . "the client library cannot convert it to the server's character set, says "
666 . 'so after the statement has run, and the row then holds a blank in place '
667 . 'of the value. Nothing was sent. Use a DBD::Sybase built against the Sybase '
668 . 'Open Client libraries with the client character set set, or keep to ASCII',
669 defined $column
670 ? sprintf('table %s, column %s: the value', $table // '(statement)', $column)
671 : sprintf('table %s, bind value %d: the value', $table // '(statement)', $position),
672 );
673 }
674  
675 304 ▶sub _prep_for_execute {
Subroutine _prep_for_execute: called CC=6 SCAR=17.9
676 304 my ($self, $op, $ident, $args) = @_;
677  
678 304 my $limit; # extract and use shortcut on limit without offset
679 304 ▶ if ($op eq 'select' and ! $args->[4] and $limit = $args->[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "select" and not $args->[4] and $limit = $args->[3]) 1 303 304
Condition83%5/6
$op eq "select" and not $args->[4] and $limit = $args->[3]
!ll&&!rl&&r
293101
$op eq "select" and not $args->[4]
!ll&&!rl&&r
293011
MC/DC66%2/3
$op eq "select" and not $args->[4] and $limit = $args->[3]
$op eq "select" not $args->[4] $limit = $args->[3]
Truth table75%3/4
A and not(B) and C
A= $op eq "select"B= not $args->[4]C= $limit = $args->[3]
ABCresult
0XX0
10X0
1100
1111
680 1 $args = [ @$args ];
681 1 $args->[3] = undef;
682 }
683  
684 304 my ($sql, $bind) = $self->next::method($op, $ident, $args);
685  
686 304 $self->_refuse_non_ascii_binds($ident, $bind);
687  
688 # $limit is already sanitized by now
689 298 ▶ $sql = join( "\n",
Branch: 1 branch
BranchTrueFalseTotal
if $limit 1 297 298
690 "SET ROWCOUNT $limit",
691 $sql,
692 "SET ROWCOUNT 0",
693 ) if $limit;
694  
695 298 ▶ if (my $identity_col = $self->_perform_autoinc_retrieval) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $identity_col = $self->_perform_autoinc_retrieval) 87 211 298
696 87 $sql .= "\n" . $self->_fetch_identity_sql($ident, $identity_col)
697 }
698  
699 298 return ($sql, $bind);
700 }
701  
702 # Stolen from SQLT, with some modifications. This is a makeshift
703 # solution before a sane type-mapping library is available, thus
704 # the 'our' for easy overrides.
705 34 our %TYPE_MAPPING = (
706 number => 'numeric',
707 money => 'money',
708 varchar => 'varchar',
709 varchar2 => 'varchar',
710 timestamp => 'datetime',
711 text => 'varchar',
712 real => 'double precision',
713 comment => 'text',
714 bit => 'bit',
715 tinyint => 'smallint',
716 float => 'double precision',
717 serial => 'numeric',
718 bigserial => 'numeric',
719 boolean => 'varchar',
720 long => 'varchar',
721 );
722  
723 27 ▶sub _native_data_type {
Subroutine _native_data_type: called CC=2 SCAR=7.0
724 27 my ($self, $type) = @_;
725  
726 27 $type = lc $type;
727 27 $type =~ s/\s* identity//x;
728  
729 27 ▶ return uc($TYPE_MAPPING{$type} || $type);
Condition66%2/3
$DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type} || $type
l!l&&r!l&&!r
1980
MC/DC0%0/2
$DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type} || $type
$DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type} $type
Truth table66%2/3
A || B
A= $DBIO::Sybase::Storage::ASE::TYPE_MAPPING{$type}B= $type
ABresult
1X1
011
000
730 }
731  
732 # handles TEXT/IMAGE and transaction for last_insert_id
733 95 ▶sub insert {
Subroutine insert: called CC=19 SCAR=29.9
Pod documented
734 95 my $self = shift;
735  
736 # the writer storage is made by _init, at the first connect (karr k67)
737 95 $self->_get_dbh;
738  
739 95 my ($source, $to_insert) = @_;
740  
741 # The hash is the caller's: the placeholders and DEFAULTs below go into a
742 # copy of it (karr k83). Scalar ref values are literal SQL and are not cloned.
743 95 $to_insert = { %$to_insert };
744  
745 95 my $columns_info = $source->columns_info;
746  
747 my $identity_col =
748 253 ▶ (first { $columns_info->{$_}{is_auto_increment} }
Subroutine __ANON__: called CC=1 SCAR=0.0
749 95 ▶ keys %$columns_info )
Condition100%2/2
&first(sub { $columns_info->{$_}{'is_auto_increment'}; } , keys %$columns_info) || ''
l!l
878
MC/DC100%1/1
&first(sub { $columns_info->{$_}{'is_auto_increment'}; } , keys %$columns_info) || ''
&first(sub { $columns_info->{$_}{'is_auto_increment'}; } , keys %$columns_info)
Truth table100%2/2
A
A= &first(sub { $columns_info->{$_}{'is_auto_increment'}; } , keys %$columns_info)
Aresult
11
00
750 || '';
751  
752 # FIXME - this is duplication from DBI.pm. When refactored towards
753 # the LobWriter this can be folded back where it belongs.
754 95 ▶ local $self->{_autoinc_supplied_for_op} = exists $to_insert->{$identity_col}
Branch: 1 branch
BranchTrueFalseTotal
exists $to_insert->{$identity_col} ? : 0 95 95
755 ? 1
756 : 0
757 ;
758 local $self->{_perform_autoinc_retrieval} =
759 95 ▶ ($identity_col and ! exists $to_insert->{$identity_col})
Branch: 1 branch
BranchTrueFalseTotal
$identity_col && !exists $to_insert->{$identity_col} ? : 87 8 95
Condition66%2/3
$identity_col and not exists $to_insert->{$identity_col}
!ll&&!rl&&r
8087
MC/DC50%1/2
$identity_col and not exists $to_insert->{$identity_col}
$identity_col not exists $to_insert->{$identity_col}
Truth table66%2/3
A and not(B)
A= $identity_colB= not exists $to_insert->{$identity_col}
ABresult
0X0
100
111
760 ? $identity_col
761 : undef
762 ;
763  
764 # check for empty insert
765 # INSERT INTO foo DEFAULT VALUES -- does not work with Sybase
766 # try to insert explicit 'DEFAULT's instead (except for identity, timestamp
767 # and computed columns)
768 95 my %defaulted;
769 95 ▶ if (not %$to_insert) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$to_insert) 4 91 95
770 4 for my $col ($source->columns) {
771 16 ▶ next if $col eq $identity_col;
Branch: 1 branch
BranchTrueFalseTotal
if $col eq $identity_col 4 12 16
772  
773 12 my $info = $source->column_info($col);
774  
775 next if ref $info->{default_value} eq 'SCALAR'
776 12 ▶ || (exists $info->{data_type} && (not defined $info->{data_type}));
Branch: 1 branch
BranchTrueFalseTotal
if ref $info->{"default_value"} eq "SCALAR" or exists $info->{"data_type"} and not defined $info->{"data_type"} 0 12 12
Condition33%2/6
ref $info->{"default_value"} eq "SCALAR" or exists $info->{"data_type"} and not defined $info->{"data_type"}
l!l&&r!l&&!r
0012
exists $info->{"data_type"} and not defined $info->{"data_type"}
!ll&&!rl&&r
0120
MC/DC0%0/3
ref $info->{"default_value"} eq "SCALAR" or exists $info->{"data_type"} and not defined $info->{"data_type"}
ref $info->{"default_value"} eq "SCALAR" exists $info->{"data_type"} not defined $info->{"data_type"}
Truth table25%1/4
A or B and not(C)
A= ref $info->{"default_value"} eq "SCALAR"B= exists $info->{"data_type"}C= not defined $info->{"data_type"}
ABCresult
1XX1
0111
00X0
0100
777  
778 12 ▶ next if $info->{data_type} && $info->{data_type} =~ /^timestamp\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"data_type"} and $info->{"data_type"} =~ /^timestamp\z/i 0 12 12
Condition33%1/3
$info->{"data_type"} and $info->{"data_type"} =~ /^timestamp\z/i
!ll&&!rl&&r
0120
MC/DC0%0/2
$info->{"data_type"} and $info->{"data_type"} =~ /^timestamp\z/i
$info->{"data_type"} $info->{"data_type"} =~ /^timestamp\z/i
Truth table33%1/3
A and B
A= $info->{"data_type"}B= $info->{"data_type"} =~ /^timestamp\z/i
ABresult
0X0
100
111
779  
780 12 $to_insert->{$col} = \'DEFAULT';
781 12 $defaulted{$col} = 1;
782 }
783 }
784  
785 # What stands in the TEXT/IMAGE columns before _remove_blob_cols puts its
786 # placeholders there. Core's insert returns the columns as it is handed
787 # them, and DBIO::Row keeps what is returned: _insert puts these back, or a
788 # row object holds the placeholder, a SCALAR ref, until it is read again
789 # (karr k79).
790 my %lob_values =
791 155 map { $_ => $to_insert->{$_} }
792 95 ▶ grep { !$defaulted{$_} && $self->_is_lob_column($source, $_) }
Condition100%3/3
!$defaulted{$_} && $self->_is_lob_column($source, $_)
!ll&&!rl&&r
1294155
MC/DC100%2/2
!$defaulted{$_} && $self->_is_lob_column($source, $_)
!$defaulted{$_} $self->_is_lob_column($source, $_)
Truth table100%3/3
not(A) && B
A= !$defaulted{$_}B= $self->_is_lob_column($source, $_)
ABresult
0X0
100
111
793 keys %$to_insert;
794  
795 95 my $blob_cols = $self->_remove_blob_cols($source, $to_insert);
796  
797 # do we need the horrific SELECT MAX(COL) hack?
798 95 ▶ my $need_dumb_last_insert_id = (
Condition100%5/5
$self->_perform_autoinc_retrieval && ($self->_identity_method || '') ne '@@IDENTITY'
!ll&&!rl&&r
81869
$self->_identity_method || ''
l!l
1869
MC/DC100%2/2
$self->_perform_autoinc_retrieval && ($self->_identity_method || '') ne '@@IDENTITY'
$self->_perform_autoinc_retrieval $self->_identity_method
Truth table100%3/3
A && B
A= $self->_perform_autoinc_retrievalB= $self->_identity_method
ABresult
0X0
100
111
799 $self->_perform_autoinc_retrieval
800 &&
801 ($self->_identity_method||'') ne '@@IDENTITY'
802 );
803  
804 95 my $next = $self->next::can;
805  
806 # we are already in a transaction, or there are no blobs
807 # and we don't need the PK - just (try to) do it
808 95 ▶ if ($self->{transaction_depth}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"transaction_depth"} or not $blob_cols || $need_dumb_last_insert_id) 31 64 95
Condition100%6/6
$self->{"transaction_depth"} or not $blob_cols || $need_dumb_last_insert_id
l!l&&r!l&&!r
171464
$blob_cols || $need_dumb_last_insert_id
l!l&&r!l&&!r
392514
MC/DC100%3/3
$self->{"transaction_depth"} or not $blob_cols || $need_dumb_last_insert_id
$self->{"transaction_depth"} $blob_cols $need_dumb_last_insert_id
Truth table100%4/4
A or not(B || C)
A= $self->{"transaction_depth"}B= $blob_colsC= $need_dumb_last_insert_id
ABCresult
1XX1
0001
01X0
0010
809 || (!$blob_cols && !$need_dumb_last_insert_id)
810 ) {
811 31 return $self->_insert (
812 $next, $source, $to_insert, $blob_cols, $identity_col, \%lob_values,
813 \%defaulted
814 );
815 }
816  
817 # otherwise use the _writer_storage to do the insert+transaction on another
818 # connection
819 64 my $guard = $self->_writer_storage->txn_scope_guard;
820  
821 64 my $updated_cols = $self->_writer_storage->_insert (
822 $next, $source, $to_insert, $blob_cols, $identity_col, \%lob_values,
823 \%defaulted
824 );
825  
826 64 $self->_identity($self->_writer_storage->_identity);
827  
828 64 $guard->commit;
829  
830 64 return $updated_cols;
831 }
832  
833 95 ▶sub _insert {
Subroutine _insert: called CC=4 SCAR=13.9
834 95 my ($self, $next, $source, $to_insert, $blob_cols, $identity_col, $lob_values, $defaulted) = @_;
835  
836 95 my $updated_cols = $self->$next ($source, $to_insert);
837  
838 93 ▶ my $final_row = {
Branch: 1 branch
BranchTrueFalseTotal
$identity_col ? : 87 6 93
839 ($identity_col ?
840 ($identity_col => $self->last_insert_id($source, $identity_col)) : ()),
841 %$to_insert,
842 %$updated_cols,
843 };
844  
845 93 ▶ $self->_insert_blobs ($source, $blob_cols, $final_row) if $blob_cols;
Branch: 1 branch
BranchTrueFalseTotal
if $blob_cols 47 46 93
846  
847 # the values of the TEXT/IMAGE columns, not their placeholders: see insert
848 93 @{$updated_cols}{ keys %$lob_values } = values %$lob_values;
849  
850 # The DEFAULT literals insert wrote for an empty insert are not values of the
851 # row: the object holds the primary key and reads the rest on demand, as
852 # after create({}) on every other driver (karr k84).
853 93 ▶ delete @{$updated_cols}{ keys %{ $defaulted || {} } };
Condition50%1/2
$defaulted || {}
l!l
930
MC/DC0%0/1
$defaulted || {}
$defaulted
Truth table50%1/2
A
A= $defaulted
Aresult
11
00
854  
855 93 return $updated_cols;
856 }
857  
858 118 ▶sub update {
Subroutine update: called CC=3 SCAR=11.0
Pod documented
859 118 my $self = shift;
860  
861 # the writer storage is made by _init, at the first connect (karr k67)
862 118 $self->_get_dbh;
863  
864 118 my ($source, $fields, $where, @rest) = @_;
865  
866 # The hash is the caller's: _remove_blob_cols and the delete below work on a
867 # copy, which is also what next::method gets (karr k83).
868 118 $fields = { %$fields };
869 118 @_ = ($source, $fields, $where, @rest);
870  
871 #
872 # When *updating* identities, ASE requires SET IDENTITY_UPDATE called
873 #
874 118 ▶ if (my $blob_cols = $self->_remove_blob_cols($source, $fields)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $blob_cols = $self->_remove_blob_cols($source, $fields)) { } 55 63 118
875  
876 # If there are any blobs in $where, Sybase will return a descriptive error
877 # message.
878 # XXX blobs can still be used with a LIKE query, and this should be handled.
879  
880 # update+blob update(s) done atomically on separate connection
881 55 $self = $self->_writer_storage;
882  
883 55 my $guard = $self->txn_scope_guard;
884  
885 # First update the blob columns to be updated to '' (taken from $fields, where
886 # it is originally put by _remove_blob_cols .)
887 55 my %blobs_to_empty = map { ($_ => delete $fields->{$_}) } keys %$blob_cols;
888  
889 # We can't only update NULL blobs, because blobs cannot be in the WHERE clause.
890 # Its row count is the one to return when no other column is left to set:
891 # $where hit that many rows, and the content write below is aimed at the
892 # same rows with the same $where, so it has no count of its own (it returns
893 # none). DBIO::Row::update takes a false count for "row not found" (k82).
894 55 my $rv = $self->next::method($source, \%blobs_to_empty, $where, @rest);
895  
896 # Now update the blobs before the other columns in case the update of other
897 # columns makes the search condition invalid.
898 55 $self->_update_blobs($source, $blob_cols, $where);
899  
900 55 ▶ if (keys %$fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$fields) { } 32 23 55
901  
902 # Now set the identity update flags for the actual update
903 local $self->{_autoinc_supplied_for_op} = grep
904 40 { $_->{is_auto_increment} }
905 32 values %{ $source->columns_info([ keys %$fields ]) }
906 ;
907  
908 32 my $next = $self->next::can;
909 32 my $args = \@_;
910 32 ▶ return preserve_context {
Subroutine __ANON__: called CC=1 SCAR=0.0
911 32 $self->$next(@$args);
912 32 ▶ } after => sub { $guard->commit };
Subroutine __ANON__: called CC=1 SCAR=0.0
913 }
914 else {
915 23 $guard->commit;
916 23 return $rv;
917 }
918 }
919 else {
920 # Set the identity update flags for the actual update
921 local $self->{_autoinc_supplied_for_op} = grep
922 95 { $_->{is_auto_increment} }
923 63 values %{ $source->columns_info([ keys %$fields ]) }
924 ;
925  
926 63 return $self->next::method(@_);
927 }
928 }
929  
930  
931 0 ▶sub connect_call_datetime_setup {
Subroutine connect_call_datetime_setup: not called CC=2 SCAR=17.9
Pod documented
932 0 my $self = shift;
933 0 my $dbh = $self->_get_dbh;
934  
935 0 ▶ if ($dbh->can('syb_date_fmt')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->can('syb_date_fmt')) { } 0 0 0
936 # amazingly, this works with FreeTDS
937 0 $dbh->syb_date_fmt('ISO_strict');
938 }
939 else {
940 0 carp_once
941 'Your DBD::Sybase is too old to support '
942 .'DBIO::InflateColumn::DateTime, please upgrade!';
943  
944 0 $dbh->do('SET DATEFORMAT mdy');
945 }
946 }
947  
948  
949 package DBIO::Sybase::Storage::ASE::DateTime::Format;
950  
951 34 ▶use base 'DBIO::Storage::DateTimeFormat';
Subroutine BEGIN: called CC=1 SCAR=0.0
952  
953 # No preferred_format_class: DateTime::Format::Sybase expects mdy in both
954 # directions, but connect_call_datetime_setup configures ISO_strict output.
955 34 __PACKAGE__->datetime_parse_pattern('%Y-%m-%dT%H:%M:%S.%3NZ');
956 34 __PACKAGE__->datetime_format_pattern('%m/%d/%Y %H:%M:%S.%3N');
957  
958 34 1;
959  
960 __END__
« Sybase/Introspect/Columns.pm ↑ Summary Sybase/Deploy.pm »