Sybase/Storage/ASE/LOBWriter.pm

filter: Statementstmt 15.6% 16 / 102 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 27.7% 5 / 18 Podpod n/a totaltotal 12.2% 21 / 171 CC 32 SCAR 34.7
CC
32
Cov
11%
__ANON__
72.0
_remove_blob_cols_array
56.0
_remove_blob_cols
42.0
CRAP 32.2
« Sybase/Storage/ASE.pm ↑ Summary Sybase/Introspect.pm »
1 package DBIO::Sybase::Storage::ASE::LOBWriter;
2 # ABSTRACT: LOB (TEXT/IMAGE) handling mixin for Sybase ASE
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use DBIO::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # No requires - these methods expect the consuming class to have:
11 # _is_lob_column, _get_dbh, _blob_log_on_update, _using_freetds
12  
13 0 ▶sub _is_lob_type {
Subroutine _is_lob_type: not called CC=2 SCAR=17.9
14 0 my ($self, $type) = @_;
15 0 ▶ return unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
16 0 $type = lc $type;
17 0 return $type =~ /^(?:text|ntext|image|blob|clob)$/;
18 }
19  
20 # Make sure blobs are not bound as placeholders, and return any non-empty ones
21 # as a hash.
22 0 ▶sub _remove_blob_cols {
Subroutine _remove_blob_cols: not called CC=6 SCAR=37.4
23 0 my ($self, $source, $fields) = @_;
24  
25 0 my %blob_cols;
26  
27 0 for my $col (keys %$fields) {
28 0 ▶ if ($self->_is_lob_column($source, $col)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_lob_column($source, $col)) 0 0 0
29 0 my $blob_val = delete $fields->{$col};
30 0 ▶ if (not defined $blob_val) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $blob_val) { } 0 0 0
31 0 $fields->{$col} = \'NULL';
32 }
33 else {
34 0 $fields->{$col} = "\'\'";
35 0 ▶ $blob_cols{$col} = $blob_val unless $blob_val eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $blob_val eq "" 0 0 0
36 }
37 }
38 }
39  
40 0 ▶ return %blob_cols ? \%blob_cols : undef;
Branch: 1 branch
BranchTrueFalseTotal
%blob_cols ? : 0 0 0
41 }
42  
43 # same for _insert_bulk
44 0 ▶sub _remove_blob_cols_array {
Subroutine _remove_blob_cols_array: not called CC=7 SCAR=40.3
45 0 my ($self, $source, $cols, $data) = @_;
46  
47 0 my @blob_cols;
48  
49 0 for my $i (0..$#$cols) {
50 0 my $col = $cols->[$i];
51  
52 0 ▶ if ($self->_is_lob_column($source, $col)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_lob_column($source, $col)) 0 0 0
53 0 for my $j (0..$#$data) {
54 0 my $blob_val = delete $data->[$j][$i];
55 0 ▶ if (not defined $blob_val) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $blob_val) { } 0 0 0
56 0 $data->[$j][$i] = \'NULL';
57 }
58 else {
59 0 $data->[$j][$i] = "\'\'";
60 0 ▶ $blob_cols[$j][$i] = $blob_val
Branch: 1 branch
BranchTrueFalseTotal
unless $blob_val eq "" 0 0 0
61 unless $blob_val eq '';
62 }
63 }
64 }
65 }
66  
67 0 ▶ return @blob_cols ? \@blob_cols : undef;
Branch: 1 branch
BranchTrueFalseTotal
@blob_cols ? : 0 0 0
68 }
69  
70 0 ▶sub _update_blobs {
Subroutine _update_blobs: not called CC=4 SCAR=30.0
71 0 my ($self, $source, $blob_cols, $where) = @_;
72  
73 my @primary_cols = try
74 0 ▶ { $source->_pri_cols_or_die }
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 $self->throw_exception("Cannot update TEXT/IMAGE column(s): $_")
77 0 };
78  
79 0 my @pks_to_update;
80 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where eq 'HASH' and @primary_cols == grep({defined $where->{$_};} @primary_cols)) { } 0 0 0
Condition0%0/3
ref $where eq "HASH" and @primary_cols == grep({defined $where->{$_};} @primary_cols)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $where eq "HASH" and @primary_cols == grep({defined $where->{$_};} @primary_cols)
ref $where eq "HASH" @primary_cols == grep({defined $where->{$_};} @primary_cols)
Truth table0%0/3
A and B
A= ref $where eq "HASH"B= @primary_cols == grep({defined $where->{$_};} @primary_cols)
ABresult
0X0
100
111
81 ref $where eq 'HASH'
82 and
83 0 @primary_cols == grep { defined $where->{$_} } @primary_cols
84 ) {
85 0 my %row_to_update;
86 0 @row_to_update{@primary_cols} = @{$where}{@primary_cols};
87 0 @pks_to_update = \%row_to_update;
88 }
89 else {
90 0 my $cursor = $self->select ($source, \@primary_cols, $where, {});
91 @pks_to_update = map {
92 0 my %row; @row{@primary_cols} = @$_; \%row
93 } $cursor->all;
94 }
95  
96 0 for my $ident (@pks_to_update) {
97 0 $self->_insert_blobs($source, $blob_cols, $ident);
98 }
99 }
100  
101 0 ▶sub _insert_blobs {
Subroutine _insert_blobs: not called CC=5 SCAR=34.0
102 0 my ($self, $source, $blob_cols, $row) = @_;
103 0 my $dbh = $self->_get_dbh;
104  
105 0 my $table = $source->name;
106  
107 0 my %row = %$row;
108 my @primary_cols = try
109 0 ▶ { $source->_pri_cols_or_die }
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 $self->throw_exception("Cannot update TEXT/IMAGE column(s): $_")
112 0 };
113  
114 $self->throw_exception('Cannot update TEXT/IMAGE column(s) without primary key values')
115 0 ▶ if ((grep { defined $row{$_} } @primary_cols) != @primary_cols);
Branch: 1 branch
BranchTrueFalseTotal
if grep({defined $row{$_};} @primary_cols) != @primary_cols 0 0 0
116  
117 # if we are 2-phase inserting a blob - there is nothing to retrieve anymore,
118 # regardless of the previous state of the flag
119 local $self->{_perform_autoinc_retrieval}
120 0 ▶ if $self->_perform_autoinc_retrieval;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_perform_autoinc_retrieval 0 0 0
121  
122 0 for my $col (keys %$blob_cols) {
123 0 my $blob = $blob_cols->{$col};
124  
125 0 my %where = map { ($_, $row{$_}) } @primary_cols;
126  
127 0 my $cursor = $self->select ($source, [$col], \%where, {});
128 0 $cursor->next;
129 0 my $sth = $cursor->sth;
130  
131 0 ▶ if (not $sth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth) 0 0 0
132 0 $self->throw_exception(
133 "Could not find row in table '$table' for blob update:\n"
134 . DBIO::Util::dump_value(\%where)
135 );
136 }
137  
138 0 ▶ try {
Subroutine __ANON__: not called CC=8 SCAR=42.8
139 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$sth->fetch and do { do { $sth->func("CS_GET", 1, "ct_data_info") or die $sth->errstr } } 0 0 0
140 0 ▶ $sth->func('CS_GET', 1, 'ct_data_info') or die $sth->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->func("CS_GET", 1, "ct_data_info") or die $sth->errstr 0 0 0
141 } while $sth->fetch;
142  
143 0 ▶ $sth->func('ct_prepare_send') or die $sth->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->func("ct_prepare_send") or die $sth->errstr 0 0 0
144  
145 0 my $log_on_update = $self->_blob_log_on_update;
146 0 ▶ $log_on_update = 1 if not defined $log_on_update;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $log_on_update 0 0 0
147  
148 0 ▶ $sth->func('CS_SET', 1, {
Branch: 1 branch
BranchTrueFalseTotal
$sth->func("CS_SET", 1, {"total_txtlen", length $blob, "log_on_update", $log_on_update}, "ct_data_info") or die $sth->errstr 0 0 0
149 total_txtlen => length($blob),
150 log_on_update => $log_on_update
151 }, 'ct_data_info') or die $sth->errstr;
152  
153 0 ▶ $sth->func($blob, length($blob), 'ct_send_data') or die $sth->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->func($blob, length $blob, "ct_send_data") or die $sth->errstr 0 0 0
154  
155 0 ▶ $sth->func('ct_finish_send') or die $sth->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$sth->func("ct_finish_send") or die $sth->errstr 0 0 0
156 }
157 0 ▶ catch {
Subroutine __ANON__: not called CC=2 SCAR=17.9
158 0 ▶ if ($self->_using_freetds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_using_freetds) { } 0 0 0
159 0 $self->throw_exception (
160 "TEXT/IMAGE operation failed, probably because you are using FreeTDS: $_"
161 );
162 }
163 else {
164 0 $self->throw_exception($_);
165 }
166 }
167 0 ▶ finally {
Subroutine __ANON__: not called CC=2 SCAR=17.9
168 0 ▶ $sth->finish if $sth;
Branch: 1 branch
BranchTrueFalseTotal
if $sth 0 0 0
169 0 };
170 }
171 }
172  
173 0 ▶sub _insert_blobs_array {
Subroutine _insert_blobs_array: not called CC=4 SCAR=30.0
174 0 my ($self, $source, $blob_cols, $cols, $data) = @_;
175  
176 0 for my $i (0..$#$data) {
177 0 my $datum = $data->[$i];
178  
179 0 my %row;
180 0 @row{ @$cols } = @$datum;
181  
182 0 my %blob_vals;
183 0 for my $j (0..$#$cols) {
184 0 ▶ if (exists $blob_cols->[$i][$j]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $blob_cols->[$i][$j]) 0 0 0
185 0 $blob_vals{ $cols->[$j] } = $blob_cols->[$i][$j];
186 }
187 }
188  
189 0 $self->_insert_blobs ($source, \%blob_vals, \%row);
190 }
191 }
192  
193 4 1;
194  
195 __END__
196  
197 =pod
198  
199 =encoding UTF-8
200  
201 =head1 NAME
202  
203 DBIO::Sybase::Storage::ASE::LOBWriter - LOB (TEXT/IMAGE) handling mixin for Sybase ASE
204  
205 =head1 VERSION
206  
207 version 0.900001
208  
209 =head1 AUTHOR
210  
211 DBIO & DBIx::Class Authors
212  
213 =head1 COPYRIGHT AND LICENSE
214  
215 Copyright (C) 2026 DBIO Authors
216 Portions Copyright (C) 2005-2025 DBIx::Class Authors
217 Based on DBIx::Class, heavily modified.
218  
219 This is free software; you can redistribute it and/or modify it under
220 the same terms as the Perl 5 programming language system itself.
221  
222 =cut
« Sybase/Storage/ASE.pm ↑ Summary Sybase/Introspect.pm »