blib/lib/DBD/File.pm

filter: Statementstmt 78.5% 407 / 518 Branchbran 55.1% 183 / 332 Conditioncond 32.8% 61 / 186 MC/DCmcdc 19.3% 22 / 114 Subroutinesub 82.6% 57 / 69 Podpod 0.0% 0 / 1 totaltotal 59.8% 730 / 1220 CC 238 SCAR 47.8
CC
238
Cov
63%
FETCH
783.4
open_data
272.0
__ANON__
110.0
CRAP 119.3
« blib/lib/DBI/DBD/Metadata.pm ↑ Summary blib/lib/DBI/Gofer/Request.pm »
1 #!/usr/bin/perl
2 # -*- perl -*-
3 #
4 # DBD::File - A base class for implementing DBI drivers that
5 # act on plain files
6 #
7 # This module is currently maintained by
8 #
9 # H.Merijn Brand & Jens Rehsack
10 #
11 # The original author is Jochen Wiedmann.
12 #
13 # Copyright (C) 2009-2026 by H.Merijn Brand & Jens Rehsack
14 # Copyright (C) 2004 by Jeff Zucker
15 # Copyright (C) 1998 by Jochen Wiedmann
16 #
17 # All rights reserved.
18 #
19 # You may distribute this module under the terms of either the GNU
20 # General Public License or the Artistic License, as specified in
21 # the Perl README file.
22  
23 448 require 5.012;
24  
25 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 448 ▶use DBI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 package DBD::File;
31  
32 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 448 ▶use base qw( DBI::DBD::SqlEngine );
Subroutine BEGIN: called CC=1 SCAR=0.0
36 448 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 448 our $VERSION = "1.656";
39  
40 448 our $drh = undef; # holds driver handle(s) once initialized
41  
42 440 ▶sub driver ($;$) {
Subroutine driver: called CC=9 SCAR=24.6
Pod undocumented
43 440 my ($class, $attr) = @_;
44  
45 # Drivers typically use a singleton object for the $drh
46 # We use a hash here to have one singleton per subclass.
47 # (Otherwise DBD::CSV and DBD::DBM, for example, would
48 # share the same driver object which would cause problems.)
49 # An alternative would be to not cache the $drh here at all
50 # and require that subclasses do that. Subclasses should do
51 # their own caching, so caching here just provides extra safety.
52 440 ▶ $drh->{$class} and return $drh->{$class};
Branch: 1 branch
BranchTrueFalseTotal
$DBD::File::drh->{$class} and return $DBD::File::drh->{$class} 0 440 440
53  
54 440 ▶ $attr ||= {};
Condition50%1/2
$attr ||= {}
l!l
4400
MC/DC0%0/1
$attr ||= {}
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
55 448 ▶ { no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
56 440 ▶ unless ($attr->{Attribution}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr->{"Attribution"}) 18 422 440
57 $class eq "DBD::File" and
58 18 ▶ $attr->{Attribution} = "$class by Jeff Zucker";
Branch: 1 branch
BranchTrueFalseTotal
$class eq "DBD::File" and $attr->{"Attribution"} = "$class by Jeff Zucker" 18 0 18
59 0 ▶ $attr->{Attribution} ||= ${$class . "::ATTRIBUTION"} ||
Condition20%1/5
$attr->{"Attribution"} ||= ${$class . '::ATTRIBUTION';} || "oops the author of $class forgot to define this"
l!l&&r!l&&!r
1800
${$class . '::ATTRIBUTION';} || "oops the author of $class forgot to define this"
l!l
00
MC/DC0%0/2
$attr->{"Attribution"} ||= ${$class . '::ATTRIBUTION';} || "oops the author of $class forgot to define this"
$attr->{"Attribution"} ${$class . '::ATTRIBUTION';}
Truth table33%1/3
A ||= B
A= $attr->{"Attribution"}B= ${$class . '::ATTRIBUTION';}
ABresult
1X1
011
000
60 "oops the author of $class forgot to define this";
61 }
62 440 ▶ $attr->{Version} ||= ${$class . "::VERSION"};
Condition33%1/3
$attr->{"Version"} ||= ${$class . '::VERSION';}
l!l&&r!l&&!r
04400
MC/DC0%0/2
$attr->{"Version"} ||= ${$class . '::VERSION';}
$attr->{"Version"} ${$class . '::VERSION';}
Truth table33%1/3
A ||= B
A= $attr->{"Version"}B= ${$class . '::VERSION';}
ABresult
1X1
011
000
63 440 ▶ $attr->{Name} or ($attr->{Name} = $class) =~ s/^DBD\:\://;
Branch: 1 branch
BranchTrueFalseTotal
$attr->{"Name"} or ($attr->{"Name"} = $class) =~ s/^DBD\:\:// 0 440 440
64 }
65  
66 440 $drh->{$class} = $class->SUPER::driver ($attr);
67  
68 # XXX inject DBD::XXX::Statement unless exists
69  
70 440 return $drh->{$class};
71 } # driver
72  
73 0 ▶sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
74 0 undef $drh;
75 } # CLONE
76  
77 # ====== DRIVER ================================================================
78  
79 package DBD::File::dr;
80  
81 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 448 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 448 our @ISA = qw( DBI::DBD::SqlEngine::dr );
87 448 our $imp_data_size = 0;
88  
89 392 ▶sub dsn_quote {
Subroutine dsn_quote: called CC=3 SCAR=11.0
90 392 my $str = shift;
91 392 ▶ ref $str and return "";
Branch: 1 branch
BranchTrueFalseTotal
ref $str and return "" 0 392 392
92 392 ▶ defined $str or return "";
Branch: 1 branch
BranchTrueFalseTotal
defined $str or return "" 248 144 392
93 248 $str =~ s/([;:\\])/\\$1/g;
94 248 return $str;
95 } # dsn_quote
96  
97 # XXX rewrite using TableConfig ...
98 116 ▶sub default_table_source { "DBD::File::TableSource::FileSystem" }
Subroutine default_table_source: called CC=1 SCAR=0.0
99  
100 1312 ▶sub connect {
Subroutine connect: called CC=10 SCAR=23.2
101 1312 my ($drh, $dbname, $user, $auth, $attr) = @_;
102  
103 # We do not (yet) care about conflicting attributes here
104 # my $dbh = DBI->connect ("dbi:CSV:f_dir=test", undef, undef, { f_dir => "text" });
105 # will test here that both test and text should exist
106 #
107 # Parsing on our own similar to parse_dsn to find attributes in 'dbname' parameter.
108 1312 ▶ if ($dbname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbname) 1004 308 1312
109 my $attr_hash = {
110 1004 map { (m/^\s* (\S+) \s*(?: =>? | , )\s* (\S*) \s*$/x) }
111 split m/;/ => $dbname };
112 1004 ▶ if (defined $attr_hash->{f_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr_hash->{"f_dir"}) 1000 4 1004
113 1000 my $f_dir = $attr_hash->{f_dir};
114 # DSN escapes the : in Windows' path, which is not accepted by -d
115 # D\\:\\\\Test\\\\DBI-01\\\\test_output_12345
116 # -> D:\\\\Test\\\\DBI-01\\\\test_output_12345
117 1000 ▶ $^O eq "MSWin32" and $f_dir =~ s{^([a-zA-Z])\\+:}{$1:};
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "MSWin32" and $f_dir =~ s/^([a-zA-Z])\\+:/$1:/ 0 1000 1000
118 1000 ▶ unless (-d $f_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $f_dir) 8 992 1000
119 8 my $msg = "No such directory '$attr_hash->{f_dir}";
120 8 $drh->set_err (2, $msg);
121 8 ▶ $attr_hash->{RaiseError} and croak $msg;
Branch: 1 branch
BranchTrueFalseTotal
$attr_hash->{"RaiseError"} and croak($msg) 8 0 8
122 0 return;
123 }
124 }
125 }
126 1304 ▶ if ($attr and defined $attr->{f_dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr and defined $attr->{"f_dir"}) 224 1080 1304
Condition66%2/3
$attr and defined $attr->{"f_dir"}
!ll&&!rl&&r
01080224
MC/DC50%1/2
$attr and defined $attr->{"f_dir"}
$attr defined $attr->{"f_dir"}
Truth table66%2/3
A and B
A= $attrB= defined $attr->{"f_dir"}
ABresult
0X0
100
111
127 224 my $f_dir = $attr->{f_dir};
128 224 ▶ $^O eq "MSWin32" and $f_dir =~ s{^([a-zA-Z])\\+:}{$1:};
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "MSWin32" and $f_dir =~ s/^([a-zA-Z])\\+:/$1:/ 0 224 224
129 224 ▶ unless (-d $f_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $f_dir) 56 168 224
130 56 my $msg = "No such directory '$attr->{f_dir}";
131 56 $drh->set_err (2, $msg);
132 56 return;
133 }
134 }
135  
136 1248 return $drh->SUPER::connect ($dbname, $user, $auth, $attr);
137 } # connect
138  
139 440 ▶sub disconnect_all {
Subroutine disconnect_all: called CC=1 SCAR=0.0
140 } # disconnect_all
141  
142 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
143 0 undef;
144 } # DESTROY
145  
146 # ====== DATABASE ==============================================================
147  
148 package DBD::File::db;
149  
150 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
151 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
152  
153 448 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 448 require File::Spec;
155 448 require Cwd;
156 448 ▶use Scalar::Util qw( refaddr ); # in CORE since 5.7.3
Subroutine BEGIN: called CC=1 SCAR=0.0
157  
158 448 our @ISA = qw( DBI::DBD::SqlEngine::db );
159 448 our $imp_data_size = 0;
160  
161 72 ▶sub data_sources {
Subroutine data_sources: called CC=4 SCAR=14.6
162 72 my ($dbh, $attr, @other) = @_;
163 72 ▶ ref ($attr) eq "HASH" or $attr = {};
Branch: 1 branch
BranchTrueFalseTotal
ref $attr eq "HASH" or $attr = {} 72 0 72
164 72 ▶ exists $attr->{f_dir} or $attr->{f_dir} = $dbh->{f_dir};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{"f_dir"} or $attr->{"f_dir"} = $dbh->{"f_dir"} 0 72 72
165 72 ▶ exists $attr->{f_dir_search} or $attr->{f_dir_search} = $dbh->{f_dir_search};
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{"f_dir_search"} or $attr->{"f_dir_search"} = $dbh->{"f_dir_search"} 0 72 72
166 72 return $dbh->SUPER::data_sources ($attr, @other);
167 } # data_source
168  
169 1248 ▶sub set_versions {
Subroutine set_versions: called CC=1 SCAR=0.0
170 1248 my $dbh = shift;
171 1248 $dbh->{f_version} = $DBD::File::VERSION;
172  
173 1248 return $dbh->SUPER::set_versions ();
174 } # set_versions
175  
176 1248 ▶sub init_valid_attributes {
Subroutine init_valid_attributes: called CC=1 SCAR=0.0
177 1248 my $dbh = shift;
178  
179 $dbh->{f_valid_attrs} = {
180 1248 f_version => 1, # DBD::File version
181 f_dir => 1, # base directory
182 f_dir_search => 1, # extended search directories
183 f_ext => 1, # file extension
184 f_schema => 1, # schema name
185 f_lock => 1, # Table locking mode
186 f_lockfile => 1, # Table lockfile extension
187 f_encoding => 1, # Encoding of the file
188 f_valid_attrs => 1, # File valid attributes
189 f_readonly_attrs => 1, # File readonly attributes
190 };
191 $dbh->{f_readonly_attrs} = {
192 1248 f_version => 1, # DBD::File version
193 f_valid_attrs => 1, # File valid attributes
194 f_readonly_attrs => 1, # File readonly attributes
195 };
196  
197 1248 return $dbh->SUPER::init_valid_attributes ();
198 } # init_valid_attributes
199  
200 2496 ▶sub init_default_attributes {
Subroutine init_default_attributes: called CC=7 SCAR=20.4
201 2496 my ($dbh, $phase) = @_;
202  
203 # must be done first, because setting flags implicitly calls $dbdname::db->STORE
204 2496 $dbh->SUPER::init_default_attributes ($phase);
205  
206 # DBI::BD::SqlEngine::dr::connect will detect old-style drivers and
207 # don't call twice
208 2496 ▶ unless (defined $phase) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $phase) 0 2496 2496
209 # we have an "old" driver here
210 0 $phase = defined $dbh->{sql_init_phase};
211 0 ▶ $phase and $phase = $dbh->{sql_init_phase};
Branch: 1 branch
BranchTrueFalseTotal
$phase and $phase = $dbh->{"sql_init_phase"} 0 0 0
212 }
213  
214 2496 ▶ if (0 == $phase) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == $phase) 1248 1248 2496
215 # f_ext should not be initialized
216 # f_map is deprecated (but might return)
217 1248 $dbh->{f_dir} = Cwd::abs_path (File::Spec->curdir ());
218  
219 1248 push @{$dbh->{sql_init_order}{90}}, "f_meta";
220  
221 # complete derived attributes, if required
222 1248 (my $drv_class = $dbh->{ImplementorClass}) =~ s/::db$//;
223 1248 my $drv_prefix = DBI->driver_prefix ($drv_class);
224 1248 ▶ if (exists $dbh->{$drv_prefix . "meta"} and !$dbh->{sql_engine_in_gofer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$dbh{$drv_prefix . 'meta'} and not $dbh->{"sql_engine_in_gofer"}) 1054 194 1248
Condition66%2/3
exists $$dbh{$drv_prefix . 'meta'} and not $dbh->{"sql_engine_in_gofer"}
!ll&&!rl&&r
19401054
MC/DC50%1/2
exists $$dbh{$drv_prefix . 'meta'} and not $dbh->{"sql_engine_in_gofer"}
exists $$dbh{$drv_prefix . 'meta'} not $dbh->{"sql_engine_in_gofer"}
Truth table66%2/3
A and not(B)
A= exists $$dbh{$drv_prefix . 'meta'}B= not $dbh->{"sql_engine_in_gofer"}
ABresult
0X0
100
111
225 1054 my $attr = $dbh->{$drv_prefix . "meta"};
226 defined $dbh->{f_valid_attrs}{f_meta}
227 1054 ▶ and $dbh->{f_valid_attrs}{f_meta} = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $dbh->{"f_valid_attrs"}{"f_meta"} and $dbh->{"f_valid_attrs"}{"f_meta"} = 1 0 1054 1054
228  
229 1054 $dbh->{f_meta} = $dbh->{$attr};
230 }
231 }
232  
233 2496 return $dbh;
234 } # init_default_attributes
235  
236 0 ▶sub validate_FETCH_attr {
Subroutine validate_FETCH_attr: not called CC=3 SCAR=24.8
237 0 my ($dbh, $attrib) = @_;
238  
239 0 ▶ $attrib eq "f_meta" and $dbh->{sql_engine_in_gofer} and $attrib = "sql_meta";
Branch: 1 branch
BranchTrueFalseTotal
$attrib eq "f_meta" and $dbh->{"sql_engine_in_gofer"} and $attrib = "sql_meta" 0 0 0
Condition0%0/3
$attrib eq "f_meta" and $dbh->{"sql_engine_in_gofer"}
!ll&&!rl&&r
000
MC/DC0%0/2
$attrib eq "f_meta" and $dbh->{"sql_engine_in_gofer"}
$attrib eq "f_meta" $dbh->{"sql_engine_in_gofer"}
Truth table0%0/3
A and B
A= $attrib eq "f_meta"B= $dbh->{"sql_engine_in_gofer"}
ABresult
0X0
100
111
240  
241 0 return $dbh->SUPER::validate_FETCH_attr ($attrib);
242 } # validate_FETCH_attr
243  
244 8820 ▶sub validate_STORE_attr {
Subroutine validate_STORE_attr: called CC=10 SCAR=24.9
245 8820 my ($dbh, $attrib, $value) = @_;
246  
247 8820 ▶ if ($attrib eq "f_dir" && defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "f_dir" and defined $value) 1164 7656 8820
Condition66%2/3
$attrib eq "f_dir" and defined $value
!ll&&!rl&&r
765601164
MC/DC50%1/2
$attrib eq "f_dir" and defined $value
$attrib eq "f_dir" defined $value
Truth table66%2/3
A and B
A= $attrib eq "f_dir"B= defined $value
ABresult
0X0
100
111
248 1164 ▶ -d $value or
Branch: 1 branch
BranchTrueFalseTotal
-d $value or return $dbh->set_err($DBI::stderr, "No such directory '${value}'") 1164 0 1164
249 return $dbh->set_err ($DBI::stderr, "No such directory '$value'");
250 1164 ▶ File::Spec->file_name_is_absolute ($value) or
Branch: 1 branch
BranchTrueFalseTotal
"File::Spec"->file_name_is_absolute($value) or $value = Cwd::abs_path($value) 1156 8 1164
251 $value = Cwd::abs_path ($value);
252 }
253  
254 8820 ▶ if ($attrib eq "f_ext") {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "f_ext") 108 8712 8820
255 108 ▶ $value eq "" || $value =~ m{^\.\w+(?:/[rR]*)?$} or
Branch: 1 branch
BranchTrueFalseTotal
$value eq "" or $value =~ m[^\.\w+(?:/[rR]*)?$] or carp("'${value}' doesn't look like a valid file extension attribute\n") 108 0 108
Condition33%1/3
$value eq "" or $value =~ m[^\.\w+(?:/[rR]*)?$]
l!l&&r!l&&!r
01080
MC/DC0%0/2
$value eq "" or $value =~ m[^\.\w+(?:/[rR]*)?$]
$value eq "" $value =~ m[^\.\w+(?:/[rR]*)?$]
Truth table33%1/3
A or B
A= $value eq ""B= $value =~ m[^\.\w+(?:/[rR]*)?$]
ABresult
1X1
011
000
256 carp "'$value' doesn't look like a valid file extension attribute\n";
257 }
258  
259 8820 ▶ $attrib eq "f_meta" and $dbh->{sql_engine_in_gofer} and $attrib = "sql_meta";
Branch: 1 branch
BranchTrueFalseTotal
$attrib eq "f_meta" and $dbh->{"sql_engine_in_gofer"} and $attrib = "sql_meta" 0 8820 8820
Condition33%1/3
$attrib eq "f_meta" and $dbh->{"sql_engine_in_gofer"}
!ll&&!rl&&r
882000
MC/DC0%0/2
$attrib eq "f_meta" and $dbh->{"sql_engine_in_gofer"}
$attrib eq "f_meta" $dbh->{"sql_engine_in_gofer"}
Truth table33%1/3
A and B
A= $attrib eq "f_meta"B= $dbh->{"sql_engine_in_gofer"}
ABresult
0X0
100
111
260  
261 8820 return $dbh->SUPER::validate_STORE_attr ($attrib, $value);
262 } # validate_STORE_attr
263  
264 24 ▶sub get_f_versions {
Subroutine get_f_versions: called CC=7 SCAR=24.8
265 24 my ($dbh, $table) = @_;
266  
267 24 my $class = $dbh->{ImplementorClass};
268 24 $class =~ s/::db$/::Table/;
269 24 my $dver;
270 24 my $dtype = "IO::File";
271 24 eval {
272 24 $dver = IO::File->VERSION ();
273  
274 # when we're still alive here, everything went ok - no need to check for $@
275 24 $dtype .= " ($dver)";
276 };
277  
278 24 my $f_encoding;
279 24 ▶ if ($table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table) 0 24 24
280 0 my $meta;
281 0 ▶ $table and (undef, $meta) = $class->get_table_meta ($dbh, $table, 1);
Branch: 1 branch
BranchTrueFalseTotal
$table and (undef, $meta) = $class->get_table_meta($dbh, $table, 1) 0 0 0
282 0 ▶ $meta and $meta->{f_encoding} and $f_encoding = $meta->{f_encoding};
Branch: 1 branch
BranchTrueFalseTotal
$meta and $meta->{"f_encoding"} and $f_encoding = $meta->{"f_encoding"} 0 0 0
Condition0%0/3
$meta and $meta->{"f_encoding"}
!ll&&!rl&&r
000
MC/DC0%0/2
$meta and $meta->{"f_encoding"}
$meta $meta->{"f_encoding"}
Truth table0%0/3
A and B
A= $metaB= $meta->{"f_encoding"}
ABresult
0X0
100
111
283 } # if ($table)
284 24 ▶ $f_encoding ||= $dbh->{f_encoding};
Condition33%1/3
$f_encoding ||= $dbh->{"f_encoding"}
l!l&&r!l&&!r
0024
MC/DC0%0/2
$f_encoding ||= $dbh->{"f_encoding"}
$f_encoding $dbh->{"f_encoding"}
Truth table33%1/3
A ||= B
A= $f_encodingB= $dbh->{"f_encoding"}
ABresult
1X1
011
000
285  
286 24 ▶ $f_encoding and $dtype .= " + " . $f_encoding . " encoding";
Branch: 1 branch
BranchTrueFalseTotal
$f_encoding and $dtype .= ' + ' . $f_encoding . ' encoding' 0 24 24
287  
288 24 return sprintf "%s using %s", $dbh->{f_version}, $dtype;
289 } # get_f_versions
290  
291 # ====== STATEMENT =============================================================
292  
293 package DBD::File::st;
294  
295 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
296 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
297  
298 448 our @ISA = qw( DBI::DBD::SqlEngine::st );
299 448 our $imp_data_size = 0;
300  
301 448 my %supported_attrs = (
302 TYPE => 1,
303 PRECISION => 1,
304 NULLABLE => 1,
305 );
306  
307 3840 ▶sub FETCH {
Subroutine FETCH: called CC=32 SCAR=66.6
308 3840 my ($sth, $attr) = @_;
309  
310 3840 ▶ if ($supported_attrs{$attr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($supported_attrs{$attr}) 1356 2484 3840
311 1356 my $stmt = $sth->{sql_stmt};
312  
313 1356 ▶ if (exists $sth->{ImplementorClass} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sth->{"ImplementorClass"} and exists $sth->{"sql_stmt"} and $sth->{"sql_stmt"}->isa("SQL::Statement")) 0 1356 1356
Condition33%2/6
exists $sth->{"ImplementorClass"} and exists $sth->{"sql_stmt"} and $sth->{"sql_stmt"}->isa("SQL::Statement")
!ll&&!rl&&r
013560
exists $sth->{"ImplementorClass"} and exists $sth->{"sql_stmt"}
!ll&&!rl&&r
001356
MC/DC0%0/3
exists $sth->{"ImplementorClass"} and exists $sth->{"sql_stmt"} and $sth->{"sql_stmt"}->isa("SQL::Statement")
exists $sth->{"ImplementorClass"} exists $sth->{"sql_stmt"} $sth->{"sql_stmt"}->isa("SQL::Statement")
Truth table25%1/4
A and B and C
A= exists $sth->{"ImplementorClass"}B= exists $sth->{"sql_stmt"}C= $sth->{"sql_stmt"}->isa("SQL::Statement")
ABCresult
0XX0
10X0
1100
1111
314 exists $sth->{sql_stmt} &&
315 $sth->{sql_stmt}->isa ("SQL::Statement")) {
316  
317 # fill overall_defs unless we know
318 0 ▶ unless (exists $sth->{f_overall_defs} && ref $sth->{f_overall_defs}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $sth->{"f_overall_defs"} and ref $sth->{"f_overall_defs"}) 0 0 0
Condition0%0/3
exists $sth->{"f_overall_defs"} and ref $sth->{"f_overall_defs"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $sth->{"f_overall_defs"} and ref $sth->{"f_overall_defs"}
exists $sth->{"f_overall_defs"} ref $sth->{"f_overall_defs"}
Truth table0%0/3
A and B
A= exists $sth->{"f_overall_defs"}B= ref $sth->{"f_overall_defs"}
ABresult
0X0
100
111
319 0 my $types = $sth->{Database}{Types};
320 0 ▶ unless ($types) { # Fetch types only once per database
Branch: 1 branch
BranchTrueFalseTotal
unless ($types) 0 0 0
321 0 ▶ if (my $t = $sth->{Database}->type_info_all ()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $sth->{"Database"}->type_info_all) 0 0 0
322 0 foreach my $i (1 .. $#$t) {
323 0 $types->{uc $t->[$i][0]} = $t->[$i][1];
324 0 ▶ $types->{$t->[$i][1]} ||= uc $t->[$i][0];
Condition0%0/3
$$types{$t->[$i][1]} ||= uc $t->[$i][0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$$types{$t->[$i][1]} ||= uc $t->[$i][0]
$$types{$t->[$i][1]} uc $t->[$i][0]
Truth table0%0/3
A ||= B
A= $$types{$t->[$i][1]}B= uc $t->[$i][0]
ABresult
1X1
011
000
325 }
326 }
327 # sane defaults
328 0 for ([ 0, "" ],
329 [ 1, "CHAR" ],
330 [ 4, "INTEGER" ],
331 [ 12, "VARCHAR" ],
332 ) {
333 0 ▶ $types->{$_->[0]} ||= $_->[1];
Condition0%0/3
$$types{$_->[0]} ||= $_->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$$types{$_->[0]} ||= $_->[1]
$$types{$_->[0]} $_->[1]
Truth table0%0/3
A ||= B
A= $$types{$_->[0]}B= $_->[1]
ABresult
1X1
011
000
334 0 ▶ $types->{$_->[1]} ||= $_->[0];
Condition0%0/3
$$types{$_->[1]} ||= $_->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$$types{$_->[1]} ||= $_->[0]
$$types{$_->[1]} $_->[0]
Truth table0%0/3
A ||= B
A= $$types{$_->[1]}B= $_->[0]
ABresult
1X1
011
000
335 }
336 0 $sth->{Database}{Types} = $types;
337 }
338 my $all_meta =
339 0 $sth->{Database}->func ("*", "table_defs", "get_sql_engine_meta");
340 0 foreach my $tbl (keys %$all_meta) {
341 0 my $meta = $all_meta->{$tbl};
342 0 ▶ exists $meta->{table_defs} && ref $meta->{table_defs} or next;
Branch: 1 branch
BranchTrueFalseTotal
exists $meta->{"table_defs"} and ref $meta->{"table_defs"} or next 0 0 0
Condition0%0/3
exists $meta->{"table_defs"} and ref $meta->{"table_defs"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $meta->{"table_defs"} and ref $meta->{"table_defs"}
exists $meta->{"table_defs"} ref $meta->{"table_defs"}
Truth table0%0/3
A and B
A= exists $meta->{"table_defs"}B= ref $meta->{"table_defs"}
ABresult
0X0
100
111
343 0 foreach (keys %{$meta->{table_defs}{columns}}) {
344 0 my $field_info = $meta->{table_defs}{columns}{$_};
345 0 ▶ if (defined $field_info->{data_type} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field_info->{"data_type"} and not $field_info->{"data_type"} =~ /^[0-9]+$/) 0 0 0
Condition0%0/3
defined $field_info->{"data_type"} and not $field_info->{"data_type"} =~ /^[0-9]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $field_info->{"data_type"} and not $field_info->{"data_type"} =~ /^[0-9]+$/
defined $field_info->{"data_type"} not $field_info->{"data_type"} =~ /^[0-9]+$/
Truth table0%0/3
A and not(B)
A= defined $field_info->{"data_type"}B= not $field_info->{"data_type"} =~ /^[0-9]+$/
ABresult
0X0
100
111
346 $field_info->{data_type} !~ m/^[0-9]+$/) {
347 0 $field_info->{type_name} = uc $field_info->{data_type};
348 0 ▶ $field_info->{data_type} = $types->{$field_info->{type_name}} || 0;
Condition0%0/2
$$types{$field_info->{'type_name'}} || 0
l!l
00
MC/DC0%0/1
$$types{$field_info->{'type_name'}} || 0
$$types{$field_info->{'type_name'}}
Truth table0%0/2
A
A= $$types{$field_info->{'type_name'}}
Aresult
11
00
349 }
350 0 ▶ $field_info->{type_name} ||= $types->{$field_info->{data_type}} || "CHAR";
Condition0%0/5
$field_info->{"type_name"} ||= $$types{$field_info->{"data_type"}} || "CHAR"
l!l&&r!l&&!r
000
$$types{$field_info->{'data_type'}} || 'CHAR'
l!l
00
MC/DC0%0/2
$field_info->{"type_name"} ||= $$types{$field_info->{"data_type"}} || "CHAR"
$field_info->{"type_name"} $$types{$field_info->{'data_type'}}
Truth table0%0/3
A ||= B
A= $field_info->{"type_name"}B= $$types{$field_info->{'data_type'}}
ABresult
1X1
011
000
351 0 $sth->{f_overall_defs}{$_} = $field_info;
352 }
353 }
354 }
355  
356 0 my @colnames = $sth->sql_get_colnames ();
357  
358 $attr eq "TYPE" and
359 0 ▶ return [ map { $sth->{f_overall_defs}{$_}{data_type} || 12 }
Branch: 1 branch
BranchTrueFalseTotal
$attr eq "TYPE" and return [map({$sth->{"f_overall_defs"}{$_}{"data_type"} or 12;} @colnames)] 0 0 0
Condition0%0/2
$sth->{'f_overall_defs'}{$_}{'data_type'} || 12
l!l
00
MC/DC0%0/1
$sth->{'f_overall_defs'}{$_}{'data_type'} || 12
$sth->{'f_overall_defs'}{$_}{'data_type'}
Truth table0%0/2
A
A= $sth->{'f_overall_defs'}{$_}{'data_type'}
Aresult
11
00
360 @colnames ];
361  
362 $attr eq "TYPE_NAME" and
363 0 ▶ return [ map { $sth->{f_overall_defs}{$_}{type_name} || "VARCHAR" }
Branch: 1 branch
BranchTrueFalseTotal
$attr eq "TYPE_NAME" and return [map({$sth->{"f_overall_defs"}{$_}{"type_name"} or "VARCHAR";} @colnames)] 0 0 0
Condition0%0/2
$sth->{'f_overall_defs'}{$_}{'type_name'} || 'VARCHAR'
l!l
00
MC/DC0%0/1
$sth->{'f_overall_defs'}{$_}{'type_name'} || 'VARCHAR'
$sth->{'f_overall_defs'}{$_}{'type_name'}
Truth table0%0/2
A
A= $sth->{'f_overall_defs'}{$_}{'type_name'}
Aresult
11
00
364 @colnames ];
365  
366 $attr eq "PRECISION" and
367 0 ▶ return [ map { $sth->{f_overall_defs}{$_}{data_length} || 0 }
Branch: 1 branch
BranchTrueFalseTotal
$attr eq "PRECISION" and return [map({$sth->{"f_overall_defs"}{$_}{"data_length"} or 0;} @colnames)] 0 0 0
Condition0%0/2
$sth->{'f_overall_defs'}{$_}{'data_length'} || 0
l!l
00
MC/DC0%0/1
$sth->{'f_overall_defs'}{$_}{'data_length'} || 0
$sth->{'f_overall_defs'}{$_}{'data_length'}
Truth table0%0/2
A
A= $sth->{'f_overall_defs'}{$_}{'data_length'}
Aresult
11
00
368 @colnames ];
369  
370 $attr eq "NULLABLE" and
371 0 ▶ return [ map { ( grep { $_ eq "NOT NULL" }
Branch: 1 branch
BranchTrueFalseTotal
$attr eq "NULLABLE" and return [map({grep({$_ eq "NOT NULL";} @{$sth->{"f_overall_defs"}{$_}{"constraints"} or [];}) ? 0 : 1;} @colnames)] 0 0 0
372 0 ▶ @{ $sth->{f_overall_defs}{$_}{constraints} || [] })
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq 'NOT NULL';} @{$sth->{'f_overall_defs'}{$_}{'constraints'} or [];}) ? : 0 0 0
Condition0%0/2
$sth->{'f_overall_defs'}{$_}{'constraints'} || []
l!l
00
MC/DC0%0/1
$sth->{'f_overall_defs'}{$_}{'constraints'} || []
$sth->{'f_overall_defs'}{$_}{'constraints'}
Truth table0%0/2
A
A= $sth->{'f_overall_defs'}{$_}{'constraints'}
Aresult
11
00
373 ? 0 : 1 }
374 @colnames ];
375 }
376 }
377  
378 3840 return $sth->SUPER::FETCH ($attr);
379 } # FETCH
380  
381 # ====== TableSource ===========================================================
382  
383 package DBD::File::TableSource::FileSystem;
384  
385 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
386 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
387  
388 448 ▶use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
389  
390 448 our @ISA = "DBI::DBD::SqlEngine::TableSource";
391  
392 80 ▶sub data_sources {
Subroutine data_sources: called CC=17 SCAR=33.9
393 80 my ($class, $drh, $attr) = @_;
394 my $dir = $attr && exists $attr->{f_dir}
395 ? $attr->{f_dir}
396 80 ▶ : File::Spec->curdir ();
Branch: 1 branch
BranchTrueFalseTotal
$attr && exists $attr->{'f_dir'} ? : 80 0 80
Condition33%1/3
$attr and exists $attr->{"f_dir"}
!ll&&!rl&&r
0080
MC/DC0%0/2
$attr and exists $attr->{"f_dir"}
$attr exists $attr->{"f_dir"}
Truth table33%1/3
A and B
A= $attrB= exists $attr->{"f_dir"}
ABresult
0X0
100
111
397 80 ▶ defined $dir or return; # Stream-based databases do not have f_dir
Branch: 1 branch
BranchTrueFalseTotal
defined $dir or return 80 0 80
398 80 ▶ unless (-d $dir && -r $dir && -x $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir and -r $dir and -x $dir) 0 80 80
Condition33%2/6
-d $dir and -r $dir and -x $dir
!ll&&!rl&&r
0080
-d $dir and -r $dir
!ll&&!rl&&r
0080
MC/DC0%0/3
-d $dir and -r $dir and -x $dir
-d $dir -r $dir -x $dir
Truth table25%1/4
A and B and C
A= -d $dirB= -r $dirC= -x $dir
ABCresult
0XX0
10X0
1100
1111
399 0 $drh->set_err ($DBI::stderr, "Cannot use directory $dir from f_dir");
400 0 return;
401 }
402 80 my %attrs;
403 80 ▶ $attr and %attrs = %$attr;
Branch: 1 branch
BranchTrueFalseTotal
$attr and %attrs = %$attr 80 0 80
404 80 delete $attrs{f_dir};
405 80 my $dsn_quote = $drh->{ImplementorClass}->can ("dsn_quote");
406 80 my $dsnextra = join ";", map { $_ . "=" . &{$dsn_quote} ($attrs{$_}) } keys %attrs;
407 80 my @dir = ($dir);
408 $attr->{f_dir_search} && ref $attr->{f_dir_search} eq "ARRAY" and
409 0 ▶ push @dir, grep { -d $_ } @{$attr->{f_dir_search}};
Branch: 1 branch
BranchTrueFalseTotal
$attr->{"f_dir_search"} and ref $attr->{"f_dir_search"} eq "ARRAY" and push @dir, grep({-d $_;} @{$$attr{"f_dir_search"};}) 0 80 80
Condition33%1/3
$attr->{"f_dir_search"} and ref $attr->{"f_dir_search"} eq "ARRAY"
!ll&&!rl&&r
8000
MC/DC0%0/2
$attr->{"f_dir_search"} and ref $attr->{"f_dir_search"} eq "ARRAY"
$attr->{"f_dir_search"} ref $attr->{"f_dir_search"} eq "ARRAY"
Truth table33%1/3
A and B
A= $attr->{"f_dir_search"}B= ref $attr->{"f_dir_search"} eq "ARRAY"
ABresult
0X0
100
111
410 80 my @dsns;
411 80 foreach $dir (@dir) {
412 80 my $dirh = IO::Dir->new ($dir);
413 80 ▶ unless (defined $dirh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dirh) 0 80 80
414 0 $drh->set_err ($DBI::stderr, "Cannot open directory $dir: $!");
415 0 return;
416 }
417  
418 80 my ($file, %names, $driver);
419 80 ▶ $driver = $drh->{ImplementorClass} =~ m/^dbd\:\:([^\:]+)\:\:/i ? $1 : "File";
Branch: 1 branch
BranchTrueFalseTotal
$drh->{'ImplementorClass'} =~ /^dbd\:\:([^\:]+)\:\:/i ? : 80 0 80
420  
421 80 ▶ while (defined ($file = $dirh->read ())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($file = $dirh->read)) 240 80 320
422 240 my $d = File::Spec->catdir ($dir, $file);
423 # allow current dir ... it can be a data_source too
424 $file ne File::Spec->updir () && -d $d and
425 240 ▶ push @dsns, "DBI:$driver:f_dir=" . &{$dsn_quote} ($d) . ($dsnextra ? ";$dsnextra" : "");
Branch: 2 branches
BranchTrueFalseTotal
$file ne "File::Spec"->updir and -d $d and push @dsns, "DBI:${driver}:f_dir=" . &{$dsn_quote;}($d) . ($dsnextra ? ";$dsnextra" : "") 160 80 240
$dsnextra ? : 160 0 160
Condition66%2/3
$file ne "File::Spec"->updir and -d $d
!ll&&!rl&&r
800160
MC/DC50%1/2
$file ne "File::Spec"->updir and -d $d
$file ne "File::Spec"->updir -d $d
Truth table66%2/3
A and B
A= $file ne "File::Spec"->updirB= -d $d
ABresult
0X0
100
111
426 }
427 }
428 80 return @dsns;
429 } # data_sources
430  
431 36 ▶sub avail_tables {
Subroutine avail_tables: called CC=14 SCAR=27.5
432 36 my ($self, $dbh) = @_;
433  
434 36 my $dir = $dbh->{f_dir};
435 36 ▶ defined $dir or return; # Stream based db's cannot be queried for tables
Branch: 1 branch
BranchTrueFalseTotal
defined $dir or return 36 0 36
436  
437 36 my %seen;
438 my @tables;
439 36 my @dir = ($dir);
440 $dbh->{f_dir_search} && ref $dbh->{f_dir_search} eq "ARRAY" and
441 36 ▶ push @dir, grep { -d $_ } @{$dbh->{f_dir_search}};
Branch: 1 branch
BranchTrueFalseTotal
$dbh->{"f_dir_search"} and ref $dbh->{"f_dir_search"} eq "ARRAY" and push @dir, grep({-d $_;} @{$$dbh{"f_dir_search"};}) 4 32 36
Condition66%2/3
$dbh->{"f_dir_search"} and ref $dbh->{"f_dir_search"} eq "ARRAY"
!ll&&!rl&&r
3204
MC/DC50%1/2
$dbh->{"f_dir_search"} and ref $dbh->{"f_dir_search"} eq "ARRAY"
$dbh->{"f_dir_search"} ref $dbh->{"f_dir_search"} eq "ARRAY"
Truth table66%2/3
A and B
A= $dbh->{"f_dir_search"}B= ref $dbh->{"f_dir_search"} eq "ARRAY"
ABresult
0X0
100
111
442 36 foreach $dir (@dir) {
443 40 my $dirh = IO::Dir->new ($dir);
444  
445 40 ▶ unless (defined $dirh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dirh) 0 40 40
446 0 $dbh->set_err ($DBI::stderr, "Cannot open directory $dir: $!");
447 0 return;
448 }
449  
450 40 my $class = $dbh->FETCH ("ImplementorClass");
451 40 $class =~ s/::db$/::Table/;
452 40 my ($file, %names);
453 my $schema = exists $dbh->{f_schema}
454 ? defined $dbh->{f_schema} && $dbh->{f_schema} ne ""
455 ? $dbh->{f_schema} : undef
456 40 ▶ : eval { getpwuid ((stat $dir)[4]) }; # XXX Win32::pwent
Branch: 2 branches
BranchTrueFalseTotal
exists $dbh->{'f_schema'} ? : 16 24 40
defined $dbh->{'f_schema'} && $dbh->{'f_schema'} ne '' ? : 0 16 16
Condition33%1/3
defined $dbh->{"f_schema"} and $dbh->{"f_schema"} ne ""
!ll&&!rl&&r
1600
MC/DC0%0/2
defined $dbh->{"f_schema"} and $dbh->{"f_schema"} ne ""
defined $dbh->{"f_schema"} $dbh->{"f_schema"} ne ""
Truth table33%1/3
A and B
A= defined $dbh->{"f_schema"}B= $dbh->{"f_schema"} ne ""
ABresult
0X0
100
111
457 40 ▶ while (defined ($file = $dirh->read ())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($file = $dirh->read)) 176 40 216
458 176 ▶ my ($tbl, $meta) = $class->get_table_meta ($dbh, $file, 0, 0) or next; # XXX
Branch: 1 branch
BranchTrueFalseTotal
() = $class->get_table_meta($dbh, $file, 0, 0) or next 48 128 176
459 # $tbl && $meta && -f $meta->{f_fqfn} or next;
460 48 ▶ $seen{$schema // "\0"}{$dir}{$tbl}++ or
Branch: 1 branch
BranchTrueFalseTotal
$seen{$schema // "\0"}{$dir}{$tbl}++ or push @tables, [undef, $schema, $tbl, "TABLE", "FILE"] 0 48 48
Condition100%2/2
$schema // "\0"
l!l
1632
MC/DC100%1/1
$schema // "\0"
$schema
Truth table100%2/2
A
A= $schema
Aresult
11
00
461 push @tables, [ undef, $schema, $tbl, "TABLE", "FILE" ];
462 }
463 40 ▶ $dirh->close () or
Branch: 1 branch
BranchTrueFalseTotal
$dirh->close or $dbh->set_err($DBI::stderr, "Cannot close directory ${dir}: $!") 40 0 40
464 $dbh->set_err ($DBI::stderr, "Cannot close directory $dir: $!");
465 }
466  
467 36 return @tables;
468 } # avail_tables
469  
470 # ====== DataSource ============================================================
471  
472 package DBD::File::DataSource::Stream;
473  
474 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
475 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
476  
477 448 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
478  
479 448 our @ISA = "DBI::DBD::SqlEngine::DataSource";
480  
481 # We may have a working flock () built-in but that doesn't mean that locking
482 # will work on NFS (flock () may hang hard)
483 448 my $locking = eval {
484 448 my $fh;
485 448 my $nulldevice = File::Spec->devnull ();
486 448 ▶ open $fh, ">", $nulldevice or croak "Can't open $nulldevice: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $nulldevice or croak("Can't open ${nulldevice}: $!") 448 0 448
487 448 flock $fh, 0;
488 448 close $fh;
489 448 1;
490 };
491  
492 0 ▶sub complete_table_name {
Subroutine complete_table_name: not called CC=5 SCAR=34.0
493 0 my ($self, $meta, $file, $respect_case) = @_;
494  
495 0 my $tbl = $file;
496 0 ▶ if (!$respect_case and $meta->{sql_identifier_case} == 1) { # XXX SQL_IC_UPPER
Branch: 2 branches
BranchTrueFalseTotal
if (not $respect_case and $meta->{'sql_identifier_case'} == 1) { } 0 0 0
elsif (not $respect_case and $meta->{'sql_identifier_case'} == 2) { } 0 0 0
Condition0%0/3
not $respect_case and $meta->{"sql_identifier_case"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $respect_case and $meta->{"sql_identifier_case"} == 1
not $respect_case $meta->{"sql_identifier_case"} == 1
Truth table0%0/3
not(A) and B
A= not $respect_caseB= $meta->{"sql_identifier_case"} == 1
ABresult
0X0
100
111
497 0 $tbl = uc $tbl;
498 }
499 ▶ elsif (!$respect_case and $meta->{sql_identifier_case} == 2) { # XXX SQL_IC_LOWER
Condition0%0/3
not $respect_case and $meta->{"sql_identifier_case"} == 2
!ll&&!rl&&r
000
MC/DC0%0/2
not $respect_case and $meta->{"sql_identifier_case"} == 2
not $respect_case $meta->{"sql_identifier_case"} == 2
Truth table0%0/3
not(A) and B
A= not $respect_caseB= $meta->{"sql_identifier_case"} == 2
ABresult
0X0
100
111
500 0 $tbl = lc $tbl;
501 }
502  
503 0 $meta->{f_fqfn} = undef;
504 0 $meta->{f_fqbn} = undef;
505 0 $meta->{f_fqln} = undef;
506  
507 0 $meta->{table_name} = $tbl;
508  
509 0 return $tbl;
510 } # complete_table_name
511  
512 44 ▶sub apply_encoding {
Subroutine apply_encoding: called CC=5 SCAR=20.1
513 44 my ($self, $meta, $fn) = @_;
514 44 ▶ $fn //= "file handle " . fileno ($meta->{fh});
Condition50%1/2
$fn //= 'file handle ' . fileno($meta->{"fh"})
l!l
044
MC/DC0%0/1
$fn //= 'file handle ' . fileno($meta->{"fh"})
$fn
Truth table50%1/2
A
A= $fn
Aresult
11
00
515 44 ▶ if (my $enc = $meta->{f_encoding}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $enc = $meta->{'f_encoding'}) { } 44 0 44
516 44 ▶ binmode $meta->{fh}, ":encoding($enc)" or
Branch: 1 branch
BranchTrueFalseTotal
binmode $meta->{"fh"}, ":encoding($enc)" or croak("Failed to set encoding layer '${enc}' on ${fn}: $!") 44 0 44
517 croak "Failed to set encoding layer '$enc' on $fn: $!";
518 }
519 else {
520 0 ▶ binmode $meta->{fh} or croak "Failed to set binary mode on $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
binmode $meta->{"fh"} or croak("Failed to set binary mode on ${fn}: $!") 0 0 0
521 }
522 } # apply_encoding
523  
524 0 ▶sub open_data {
Subroutine open_data: not called CC=16 SCAR=56.1
525 0 my ($self, $meta, $attrs, $flags) = @_;
526  
527 0 ▶ $flags->{dropMode} and croak "Can't drop a table in stream";
Branch: 1 branch
BranchTrueFalseTotal
$flags->{"dropMode"} and croak("Can't drop a table in stream") 0 0 0
528 0 my $fn = "file handle " . fileno ($meta->{f_file});
529  
530 0 ▶ if ($flags->{createMode} || $flags->{lockMode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{'createMode'} or $flags->{'lockMode'}) { } 0 0 0
Condition0%0/3
$flags->{"createMode"} or $flags->{"lockMode"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags->{"createMode"} or $flags->{"lockMode"}
$flags->{"createMode"} $flags->{"lockMode"}
Truth table0%0/3
A or B
A= $flags->{"createMode"}B= $flags->{"lockMode"}
ABresult
1X1
011
000
531 0 ▶ $meta->{fh} = IO::Handle->new_from_fd (fileno ($meta->{f_file}), "w+") or
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"fh"} = "IO::Handle"->new_from_fd(fileno $meta->{"f_file"}, "w+") or croak("Cannot open $fn for writing: $! (" . ($! + 0) . ')') 0 0 0
532 croak "Cannot open $fn for writing: $! (" . ($!+0) . ")";
533 }
534 else {
535 0 ▶ $meta->{fh} = IO::Handle->new_from_fd (fileno ($meta->{f_file}), "r") or
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"fh"} = "IO::Handle"->new_from_fd(fileno $meta->{"f_file"}, "r") or croak("Cannot open $fn for reading: $! (" . ($! + 0) . ')') 0 0 0
536 croak "Cannot open $fn for reading: $! (" . ($!+0) . ")";
537 }
538  
539 0 ▶ if ($meta->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"fh"}) 0 0 0
540 0 $self->apply_encoding ($meta, $fn);
541 } # have $meta->{$fh}
542  
543 0 ▶ if ($self->can_flock && $meta->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can_flock and $meta->{"fh"}) 0 0 0
Condition0%0/3
$self->can_flock and $meta->{"fh"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can_flock and $meta->{"fh"}
$self->can_flock $meta->{"fh"}
Truth table0%0/3
A and B
A= $self->can_flockB= $meta->{"fh"}
ABresult
0X0
100
111
544 my $lm = defined $flags->{f_lock}
545 && $flags->{f_lock} =~ m/^[012]$/
546 ? $flags->{f_lock}
547 0 ▶ : $flags->{lockMode} ? 2 : 1;
Branch: 2 branches
BranchTrueFalseTotal
defined $flags->{'f_lock'} && $flags->{'f_lock'} =~ /^[012]$/ ? : 0 0 0
$flags->{'lockMode'} ? : 0 0 0
Condition0%0/3
defined $flags->{"f_lock"} and $flags->{"f_lock"} =~ /^[012]$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $flags->{"f_lock"} and $flags->{"f_lock"} =~ /^[012]$/
defined $flags->{"f_lock"} $flags->{"f_lock"} =~ /^[012]$/
Truth table0%0/3
A and B
A= defined $flags->{"f_lock"}B= $flags->{"f_lock"} =~ /^[012]$/
ABresult
0X0
100
111
548 0 ▶ if ($lm == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lm == 2) { } 0 0 0
elsif ($lm == 1) { } 0 0 0
549 0 ▶ flock $meta->{fh}, 2 or croak "Cannot obtain exclusive lock on $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $meta->{"fh"}, 2 or croak("Cannot obtain exclusive lock on ${fn}: $!") 0 0 0
550 }
551 elsif ($lm == 1) {
552 0 ▶ flock $meta->{fh}, 1 or croak "Cannot obtain shared lock on $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $meta->{"fh"}, 1 or croak("Cannot obtain shared lock on ${fn}: $!") 0 0 0
553 }
554 # $lm = 0 is forced no locking at all
555 }
556 } # open_data
557  
558 864 ▶sub can_flock { $locking }
Subroutine can_flock: called CC=1 SCAR=0.0
559  
560 package DBD::File::DataSource::File;
561  
562 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
563 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
564  
565 448 our @ISA = "DBD::File::DataSource::Stream";
566  
567 448 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
568 448 require List::Util;
569  
570 448 my $fn_any_ext_regex = qr/\.[^.]*/;
571  
572 878 ▶sub complete_table_name {
Subroutine complete_table_name: called CC=42 SCAR=42.1
573 878 my ($self, $meta, $file, $respect_case, $file_is_table) = @_;
574  
575 878 ▶ $file eq "." || $file eq ".." and return; # XXX would break a possible DBD::Dir
Branch: 1 branch
BranchTrueFalseTotal
$file eq "." || $file eq ".." and return 80 798 878
Condition100%3/3
$file eq "." or $file eq ".."
l!l&&r!l&&!r
4040798
MC/DC100%2/2
$file eq "." or $file eq ".."
$file eq "." $file eq ".."
Truth table100%3/3
A or B
A= $file eq "."B= $file eq ".."
ABresult
1X1
011
000
576  
577 # XXX now called without proving f_fqfn first ...
578 798 my ($ext, $req) = ("", 0);
579 798 ▶ if ($meta->{f_ext}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"f_ext"}) 756 42 798
580 756 ($ext, my $opt) = split m{/}, $meta->{f_ext};
581 756 ▶ if ($ext && $opt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext and $opt) 620 136 756
Condition66%2/3
$ext and $opt
!ll&&!rl&&r
0136620
MC/DC50%1/2
$ext and $opt
$ext $opt
Truth table66%2/3
A and B
A= $extB= $opt
ABresult
0X0
100
111
582 620 ▶ $opt =~ m/r/i and $req = 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt =~ /r/i and $req = 1 620 0 620
583 }
584 }
585  
586 # (my $tbl = $file) =~ s/\Q$ext\E$//i;
587 798 my ($tbl, $basename, $dir, $fn_ext, $user_spec_file, $searchdir);
588 798 ▶ if ($file_is_table and defined $meta->{f_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file_is_table and defined $meta->{'f_file'}) { } 8 790 798
Condition100%3/3
$file_is_table and defined $meta->{"f_file"}
!ll&&!rl&&r
1006908
MC/DC100%2/2
$file_is_table and defined $meta->{"f_file"}
$file_is_table defined $meta->{"f_file"}
Truth table100%3/3
A and B
A= $file_is_tableB= defined $meta->{"f_file"}
ABresult
0X0
100
111
589 8 $tbl = $file;
590 8 ($basename, $dir, $fn_ext) = File::Basename::fileparse ($meta->{f_file}, $fn_any_ext_regex);
591 8 $file = $basename . $fn_ext;
592 8 $user_spec_file = 1;
593 }
594 else {
595 790 ($basename, $dir, undef) = File::Basename::fileparse ($file, qr{\Q$ext\E});
596 # $dir is returned with trailing (back)slash. We just need to check
597 # if it is ".", "./", or ".\" or "[]" (VMS)
598 790 ▶ if ($dir =~ m{^(?:[.][/\\]?|\[\])$} && ref $meta->{f_dir_search} eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ m(^(?:[.][/\\]?|\[\])$) and ref $meta->{"f_dir_search"} eq "ARRAY") 36 754 790
Condition66%2/3
$dir =~ m(^(?:[.][/\\]?|\[\])$) and ref $meta->{"f_dir_search"} eq "ARRAY"
!ll&&!rl&&r
075436
MC/DC50%1/2
$dir =~ m(^(?:[.][/\\]?|\[\])$) and ref $meta->{"f_dir_search"} eq "ARRAY"
$dir =~ m(^(?:[.][/\\]?|\[\])$) ref $meta->{"f_dir_search"} eq "ARRAY"
Truth table66%2/3
A and B
A= $dir =~ m(^(?:[.][/\\]?|\[\])$)B= ref $meta->{"f_dir_search"} eq "ARRAY"
ABresult
0X0
100
111
599 36 foreach my $d ($meta->{f_dir}, @{$meta->{f_dir_search}}) {
600 60 my $f = File::Spec->catdir ($d, $file);
601 60 ▶ -f $f or next;
Branch: 1 branch
BranchTrueFalseTotal
-f $f or next 24 36 60
602 24 $searchdir = Cwd::abs_path ($d);
603 24 $dir = "";
604 24 last;
605 }
606 }
607 790 $file = $tbl = $basename;
608 790 $user_spec_file = 0;
609 }
610  
611 798 ▶ if (!$respect_case and $meta->{sql_identifier_case} == 1) { # XXX SQL_IC_UPPER
Branch: 2 branches
BranchTrueFalseTotal
if (not $respect_case and $meta->{'sql_identifier_case'} == 1) { } 16 782 798
elsif (not $respect_case and $meta->{'sql_identifier_case'} == 2) { } 782 0 782
Condition66%2/3
not $respect_case and $meta->{"sql_identifier_case"} == 1
!ll&&!rl&&r
078216
MC/DC50%1/2
not $respect_case and $meta->{"sql_identifier_case"} == 1
not $respect_case $meta->{"sql_identifier_case"} == 1
Truth table66%2/3
not(A) and B
A= not $respect_caseB= $meta->{"sql_identifier_case"} == 1
ABresult
0X0
100
111
612 16 $basename = uc $basename;
613 16 $tbl = uc $tbl;
614 }
615 ▶ elsif (!$respect_case and $meta->{sql_identifier_case} == 2) { # XXX SQL_IC_LOWER
Condition33%1/3
not $respect_case and $meta->{"sql_identifier_case"} == 2
!ll&&!rl&&r
00782
MC/DC0%0/2
not $respect_case and $meta->{"sql_identifier_case"} == 2
not $respect_case $meta->{"sql_identifier_case"} == 2
Truth table33%1/3
not(A) and B
A= not $respect_caseB= $meta->{"sql_identifier_case"} == 2
ABresult
0X0
100
111
616 782 $basename = lc $basename;
617 782 $tbl = lc $tbl;
618 }
619  
620 798 ▶ unless (defined $searchdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $searchdir) 774 24 798
621 $searchdir = File::Spec->file_name_is_absolute ($dir)
622 ? ($dir =~ s{/$}{}, $dir)
623 774 ▶ : Cwd::abs_path (File::Spec->catdir ($meta->{f_dir}, $dir));
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($dir) ? : 8 766 774
624 }
625 798 ▶ -d $searchdir or
Branch: 1 branch
BranchTrueFalseTotal
-d $searchdir or croak("-d ${searchdir}: $!") 798 0 798
626 croak "-d $searchdir: $!";
627  
628 # If the file location is outside the current folder,
629 # its absolute path should be in ($f_dir, @f_dir_search)
630 # Note this triggers only when *used*, not at definition time
631 # $dbh->{csv_tables}{foo}{file} = "/out/side/scope/foo.csv"; # OK
632 # $dbh->do ("create table foo (c char)"); # FAIL
633 798 ▶ my @bases = map { Cwd::abs_path ($_) } $meta->{f_dir}, @{$meta->{f_dir_search} || []};
Condition100%2/2
$meta->{'f_dir_search'} || []
l!l
40758
MC/DC100%1/1
$meta->{'f_dir_search'} || []
$meta->{'f_dir_search'}
Truth table100%2/2
A
A= $meta->{'f_dir_search'}
Aresult
11
00
634 798 ▶ if ($searchdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($searchdir) 798 0 798
635 798 my $sd = Cwd::abs_path ($searchdir);
636 798 ▶ unless (List::Util::first { $_ eq $sd } @bases) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless (&List::Util::first(sub { $_ eq $sd; } , @bases)) 4 794 798
637 4 croak "Using data files in $searchdir is unsafe and not allowed.\nUse f_dir or f_dir_search.\n";
638 }
639 }
640  
641 $searchdir eq $meta->{f_dir} and
642 794 ▶ $dir = "";
Branch: 1 branch
BranchTrueFalseTotal
$searchdir eq $meta->{"f_dir"} and $dir = "" 782 12 794
643  
644 794 ▶ unless ($user_spec_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user_spec_file) 790 4 794
645 790 ▶ $file_is_table and $file = "$basename$ext";
Branch: 1 branch
BranchTrueFalseTotal
$file_is_table and $file = "$basename$ext" 690 100 790
646  
647 # Fully Qualified File Name
648 790 my $cmpsub;
649 790 ▶ if ($respect_case) {
Branch: 1 branch
BranchTrueFalseTotal
if ($respect_case) { } 0 790 790
650 0 ▶ $cmpsub = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
651 0 my ($fn, undef, $sfx) = File::Basename::fileparse ($_, $fn_any_ext_regex);
652 0 ▶ $^O eq "VMS" && $sfx eq "." and
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "VMS" and $sfx eq "." and $sfx = "" 0 0 0
Condition0%0/3
$^O eq "VMS" and $sfx eq "."
!ll&&!rl&&r
000
MC/DC0%0/2
$^O eq "VMS" and $sfx eq "."
$^O eq "VMS" $sfx eq "."
Truth table0%0/3
A and B
A= $^O eq "VMS"B= $sfx eq "."
ABresult
0X0
100
111
653 $sfx = ""; # no extension turns up as a dot
654 0 ▶ $fn eq $basename and
Branch: 1 branch
BranchTrueFalseTotal
$fn eq $basename and return lc $sfx eq lc $ext || !($req || $sfx) 0 0 0
Condition0%0/6
lc $sfx eq lc $ext || !($req || $sfx)
l!l&&r!l&&!r
000
$req || $sfx
l!l&&r!l&&!r
000
MC/DC0%0/3
lc $sfx eq lc $ext || !($req || $sfx)
lc $sfx eq lc $ext $req $sfx
Truth table0%0/4
A || not(B || C)
A= lc $sfx eq lc $extB= $reqC= $sfx
ABCresult
1XX1
0001
01X0
0010
655 return (lc $sfx eq lc $ext or !$req && !$sfx);
656 0 return 0;
657 }
658 0 }
659 else {
660 3674 ▶ $cmpsub = sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
661 3674 my ($fn, undef, $sfx) = File::Basename::fileparse ($_, $fn_any_ext_regex);
662 3674 ▶ $^O eq "VMS" && $sfx eq "." and
Branch: 1 branch
BranchTrueFalseTotal
$^O eq "VMS" and $sfx eq "." and $sfx = "" 0 3674 3674
Condition33%1/3
$^O eq "VMS" and $sfx eq "."
!ll&&!rl&&r
367400
MC/DC0%0/2
$^O eq "VMS" and $sfx eq "."
$^O eq "VMS" $sfx eq "."
Truth table33%1/3
A and B
A= $^O eq "VMS"B= $sfx eq "."
ABresult
0X0
100
111
663 $sfx = ""; # no extension turns up as a dot
664 3674 ▶ lc $fn eq lc $basename and
Branch: 1 branch
BranchTrueFalseTotal
lc $fn eq lc $basename and return lc $sfx eq lc $ext || !($req || $sfx) 1260 2414 3674
Condition100%6/6
lc $sfx eq lc $ext || !($req || $sfx)
l!l&&r!l&&!r
46228770
$req || $sfx
l!l&&r!l&&!r
764628
MC/DC100%3/3
lc $sfx eq lc $ext || !($req || $sfx)
lc $sfx eq lc $ext $req $sfx
Truth table100%4/4
A || not(B || C)
A= lc $sfx eq lc $extB= $reqC= $sfx
ABCresult
1XX1
0001
01X0
0010
665 return (lc $sfx eq lc $ext or !$req && !$sfx);
666 2414 return 0;
667 }
668 790 }
669  
670 790 my @f;
671 790 ▶ { my $dh = IO::Dir->new ($searchdir) or croak "Can't open '$searchdir': $!";
Branch: 1 branch
BranchTrueFalseTotal
my $dh = "IO::Dir"->new($searchdir) or croak("Can't open '${searchdir}': $!") 790 0 790
672 8 @f = sort { length $b <=> length $a }
673 790 grep { &$cmpsub ($_) }
674 $dh->read ();
675 790 ▶ $dh->close () or croak "Can't close '$searchdir': $!";
Branch: 1 branch
BranchTrueFalseTotal
$dh->close or croak("Can't close '${searchdir}': $!") 790 0 790
676 }
677 790 ▶ @f > 0 && @f <= 2 and $file = $f[0];
Branch: 1 branch
BranchTrueFalseTotal
@f > 0 and @f <= 2 and $file = $f[0] 482 308 790
Condition66%2/3
@f > 0 and @f <= 2
!ll&&!rl&&r
3080482
MC/DC50%1/2
@f > 0 and @f <= 2
@f > 0 @f <= 2
Truth table66%2/3
A and B
A= @f > 0B= @f <= 2
ABresult
0X0
100
111
678 790 ▶ !$respect_case && $meta->{sql_identifier_case} == 4 and # XXX SQL_IC_MIXED
Branch: 1 branch
BranchTrueFalseTotal
not $respect_case and $meta->{"sql_identifier_case"} == 4 and ($tbl = $file) =~ s/\Q$ext\E$//i 0 790 790
Condition33%1/3
not $respect_case and $meta->{"sql_identifier_case"} == 4
!ll&&!rl&&r
07900
MC/DC0%0/2
not $respect_case and $meta->{"sql_identifier_case"} == 4
not $respect_case $meta->{"sql_identifier_case"} == 4
Truth table33%1/3
not(A) and B
A= not $respect_caseB= $meta->{"sql_identifier_case"} == 4
ABresult
0X0
100
111
679 ($tbl = $file) =~ s/\Q$ext\E$//i;
680  
681 790 my $tmpfn = $file;
682 790 ▶ if ($ext && $req) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext and $req) 612 178 790
Condition100%3/3
$ext and $req
!ll&&!rl&&r
42136612
MC/DC100%2/2
$ext and $req
$ext $req
Truth table100%3/3
A and B
A= $extB= $req
ABresult
0X0
100
111
683 # File extension required
684 612 ▶ $tmpfn =~ s/\Q$ext\E$//i or return;
Branch: 1 branch
BranchTrueFalseTotal
$tmpfn =~ s/\Q$ext\E$//i or return 564 48 612
685 }
686 }
687  
688 746 my $fqfn = File::Spec->catfile ($searchdir, $file);
689 746 my $fqbn = File::Spec->catfile ($searchdir, $basename);
690  
691 746 $meta->{f_fqfn} = $fqfn;
692 746 $meta->{f_fqbn} = $fqbn;
693 defined $meta->{f_lockfile} && $meta->{f_lockfile} and
694 746 ▶ $meta->{f_fqln} = $meta->{f_fqbn} . $meta->{f_lockfile};
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{"f_lockfile"} and $meta->{"f_lockfile"} and $meta->{"f_fqln"} = $meta->{"f_fqbn"} . $meta->{"f_lockfile"} 604 142 746
Condition66%2/3
defined $meta->{"f_lockfile"} and $meta->{"f_lockfile"}
!ll&&!rl&&r
1420604
MC/DC50%1/2
defined $meta->{"f_lockfile"} and $meta->{"f_lockfile"}
defined $meta->{"f_lockfile"} $meta->{"f_lockfile"}
Truth table66%2/3
A and B
A= defined $meta->{"f_lockfile"}B= $meta->{"f_lockfile"}
ABresult
0X0
100
111
695  
696 746 ▶ $dir && !$user_spec_file and $tbl = File::Spec->catfile ($dir, $tbl);
Branch: 1 branch
BranchTrueFalseTotal
$dir and not $user_spec_file and $tbl = "File::Spec"->catfile($dir, $tbl) 0 746 746
Condition33%1/3
$dir and not $user_spec_file
!ll&&!rl&&r
74600
MC/DC0%0/2
$dir and not $user_spec_file
$dir not $user_spec_file
Truth table33%1/3
A and not(B)
A= $dirB= not $user_spec_file
ABresult
0X0
100
111
697  
698 746 ▶ if (-l $fqfn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $fqfn) 0 746 746
699 0 my $real = Cwd::abs_path ($fqfn);
700 0 ▶ unless (List::Util::any { $real =~ m{^\Q$_\E(?:$|/)} } @bases) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless (&List::Util::any(sub { $real =~ m[^\Q$_\E(?:$|/)]; } , @bases)) 0 0 0
701 0 croak "Data file $fqfn is a outside of f_dir f_and f_dir_search\n";
702 }
703 }
704  
705 746 $meta->{table_name} = $tbl;
706  
707 746 return $tbl;
708 } # complete_table_name
709  
710 972 ▶sub open_data {
Subroutine open_data: called CC=26 SCAR=34.5
711 972 my ($self, $meta, $attrs, $flags) = @_;
712  
713 972 ▶ defined $meta->{f_fqfn} && $meta->{f_fqfn} ne "" or croak "No filename given";
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{"f_fqfn"} and $meta->{"f_fqfn"} ne "" or croak("No filename given") 972 0 972
Condition33%1/3
defined $meta->{"f_fqfn"} and $meta->{"f_fqfn"} ne ""
!ll&&!rl&&r
00972
MC/DC0%0/2
defined $meta->{"f_fqfn"} and $meta->{"f_fqfn"} ne ""
defined $meta->{"f_fqfn"} $meta->{"f_fqfn"} ne ""
Truth table33%1/3
A and B
A= defined $meta->{"f_fqfn"}B= $meta->{"f_fqfn"} ne ""
ABresult
0X0
100
111
714  
715 972 my ($fh, $fn);
716 972 ▶ unless ($meta->{f_dontopen}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->{"f_dontopen"}) 52 920 972
717 52 $fn = $meta->{f_fqfn};
718 52 ▶ if ($flags->{createMode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{'createMode'}) { } 8 44 52
719 -f $meta->{f_fqfn} and
720 8 ▶ croak "Cannot create table $attrs->{table}: Already exists";
Branch: 1 branch
BranchTrueFalseTotal
-f $meta->{"f_fqfn"} and croak(qq[Cannot create table $attrs->{"table"}: Already exists]) 0 8 8
721 8 ▶ $fh = IO::File->new ($fn, "a+") or
Branch: 1 branch
BranchTrueFalseTotal
$fh = "IO::File"->new($fn, "a+") or croak("Cannot open $fn for writing: $! (" . ($! + 0) . ')') 8 0 8
722 croak "Cannot open $fn for writing: $! (" . ($!+0) . ")";
723 }
724 else {
725 44 ▶ unless ($fh = IO::File->new ($fn, ($flags->{lockMode} ? "r+" : "r"))) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($fh = "IO::File"->new($fn, $flags->{"lockMode"} ? "r+" : "r")) 8 36 44
$flags->{'lockMode'} ? : 24 20 44
726 8 croak "Cannot open $fn: $! (" . ($!+0) . ")";
727 }
728 }
729  
730 44 $meta->{fh} = $fh;
731  
732 44 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) 44 0 44
733 44 ▶ $fh->seek (0, 0) or
Branch: 1 branch
BranchTrueFalseTotal
$fh->seek(0, 0) or croak("Error while seeking back: $!") 44 0 44
734 croak "Error while seeking back: $!";
735  
736 44 $self->apply_encoding ($meta);
737 }
738 }
739 964 ▶ if ($meta->{f_fqln}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"f_fqln"}) 918 46 964
740 918 $fn = $meta->{f_fqln};
741 918 ▶ if ($flags->{createMode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{'createMode'}) { } 122 796 918
742 122 ▶ -f $fn and
Branch: 1 branch
BranchTrueFalseTotal
-f $fn and croak(qq[Cannot create table lock at '${fn}' for $attrs->{"table"}: Already exists]) 0 122 122
743 croak "Cannot create table lock at '$fn' for $attrs->{table}: Already exists";
744 122 ▶ $fh = IO::File->new ($fn, "a+") or
Branch: 1 branch
BranchTrueFalseTotal
$fh = "IO::File"->new($fn, "a+") or croak("Cannot open $fn for writing: $! (" . ($! + 0) . ')') 122 0 122
745 croak "Cannot open $fn for writing: $! (" . ($!+0) . ")";
746 }
747 else {
748 796 ▶ unless ($fh = IO::File->new ($fn, ($flags->{lockMode} ? "r+" : "r"))) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($fh = "IO::File"->new($fn, $flags->{"lockMode"} ? "r+" : "r")) 100 696 796
$flags->{'lockMode'} ? : 588 208 796
749 100 croak "Cannot open $fn: $! (" . ($!+0) . ")";
750 }
751 }
752  
753 818 $meta->{lockfh} = $fh;
754 }
755  
756 864 ▶ if ($self->can_flock && $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can_flock and $fh) 862 2 864
Condition66%2/3
$self->can_flock and $fh
!ll&&!rl&&r
02862
MC/DC50%1/2
$self->can_flock and $fh
$self->can_flock $fh
Truth table66%2/3
A and B
A= $self->can_flockB= $fh
ABresult
0X0
100
111
757 my $lm = defined $flags->{f_lock}
758 && $flags->{f_lock} =~ m/^[012]$/
759 ? $flags->{f_lock}
760 862 ▶ : $flags->{lockMode} ? 2 : 1;
Branch: 2 branches
BranchTrueFalseTotal
defined $flags->{'f_lock'} && $flags->{'f_lock'} =~ /^[012]$/ ? : 0 862 862
$flags->{'lockMode'} ? : 642 220 862
Condition33%1/3
defined $flags->{"f_lock"} and $flags->{"f_lock"} =~ /^[012]$/
!ll&&!rl&&r
86200
MC/DC0%0/2
defined $flags->{"f_lock"} and $flags->{"f_lock"} =~ /^[012]$/
defined $flags->{"f_lock"} $flags->{"f_lock"} =~ /^[012]$/
Truth table33%1/3
A and B
A= defined $flags->{"f_lock"}B= $flags->{"f_lock"} =~ /^[012]$/
ABresult
0X0
100
111
761 862 ▶ if ($lm == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lm == 2) { } 642 220 862
elsif ($lm == 1) { } 220 0 220
762 642 ▶ flock $fh, 2 or croak "Cannot obtain exclusive lock on $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or croak("Cannot obtain exclusive lock on ${fn}: $!") 642 0 642
763 }
764 elsif ($lm == 1) {
765 220 ▶ flock $fh, 1 or croak "Cannot obtain shared lock on $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 1 or croak("Cannot obtain shared lock on ${fn}: $!") 220 0 220
766 }
767 # $lm = 0 is forced no locking at all
768 }
769 } # open_data
770  
771 # ====== SQL::STATEMENT ========================================================
772  
773 package DBD::File::Statement;
774  
775 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
776 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
777  
778 448 our @ISA = qw( DBI::DBD::SqlEngine::Statement );
779  
780 # ====== SQL::TABLE ============================================================
781  
782 package DBD::File::Table;
783  
784 448 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
785 448 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
786  
787 448 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
788 448 require IO::File;
789 448 require File::Basename;
790 448 require File::Spec;
791 448 require Cwd;
792 448 require Scalar::Util;
793  
794 448 our @ISA = qw( DBI::DBD::SqlEngine::Table );
795  
796 # ====== UTILITIES ============================================================
797  
798 448 ▶if (eval { require Params::Util; }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Params::Util } }) { } 448 0 448
799 448 Params::Util->import ("_HANDLE");
800 }
801 else {
802 # taken but modified from Params::Util ...
803 0 ▶ *_HANDLE = sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
804 # It has to be defined, of course
805 0 ▶ defined $_[0] or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or return 0 0 0
806  
807 # Normal globs are considered to be file handles
808 0 ▶ ref $_[0] eq "GLOB" and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "GLOB" and return $_[0] 0 0 0
809  
810 # Check for a normal tied filehandle
811 # Side Note: 5.5.4's tied () and can () doesn't like getting undef
812 0 ▶ tied ($_[0]) and tied ($_[0])->can ("TIEHANDLE") and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
tied $_[0] and tied($_[0])->can("TIEHANDLE") and return $_[0] 0 0 0
Condition0%0/3
tied $_[0] and tied($_[0])->can("TIEHANDLE")
!ll&&!rl&&r
000
MC/DC0%0/2
tied $_[0] and tied($_[0])->can("TIEHANDLE")
tied $_[0] tied($_[0])->can("TIEHANDLE")
Truth table0%0/3
A and B
A= tied $_[0]B= tied($_[0])->can("TIEHANDLE")
ABresult
0X0
100
111
813  
814 # There are no other non-object handles that we support
815 0 ▶ Scalar::Util::blessed ($_[0]) or return;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) or return 0 0 0
816  
817 # Check for a common base classes for conventional IO::Handle object
818 0 ▶ $_[0]->isa ("IO::Handle") and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("IO::Handle") and return $_[0] 0 0 0
819  
820 # Check for tied file handles using Tie::Handle
821 0 ▶ $_[0]->isa ("Tie::Handle") and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("Tie::Handle") and return $_[0] 0 0 0
822  
823 # IO::Scalar is not a proper seekable, but it is valid is a
824 # regular file handle
825 0 ▶ $_[0]->isa ("IO::Scalar") and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("IO::Scalar") and return $_[0] 0 0 0
826  
827 # Yet another special case for IO::String, which refuses (for now
828 # anyway) to become a subclass of IO::Handle.
829 0 ▶ $_[0]->isa ("IO::String") and return $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("IO::String") and return $_[0] 0 0 0
830  
831 # This is not any sort of object we know about
832 0 return;
833 0 };
834 }
835  
836 # ====== FLYWEIGHT SUPPORT =====================================================
837  
838 # Flyweight support for table_info
839 # The functions file2table, init_table_meta, default_table_meta and
840 # get_table_meta are using $self arguments for polymorphism only. The
841 # must not rely on an instantiated DBD::File::Table
842 0 ▶sub file2table {
Subroutine file2table: not called CC=1 SCAR=6.9
843 0 my ($self, $meta, $file, $file_is_table, $respect_case) = @_;
844  
845 0 return $meta->{sql_data_source}->complete_table_name ($meta, $file, $respect_case, $file_is_table);
846 } # file2table
847  
848 894 ▶sub bootstrap_table_meta {
Subroutine bootstrap_table_meta: called CC=11 SCAR=24.0
849 894 my ($self, $dbh, $meta, $table, @other) = @_;
850  
851 894 $self->SUPER::bootstrap_table_meta ($dbh, $meta, $table, @other);
852  
853 894 ▶ exists $meta->{f_dir} or $meta->{f_dir} = $dbh->{f_dir};
Branch: 1 branch
BranchTrueFalseTotal
exists $meta->{"f_dir"} or $meta->{"f_dir"} = $dbh->{"f_dir"} 54 840 894
854 894 ▶ exists $meta->{f_dir_search} or $meta->{f_dir_search} = $dbh->{f_dir_search};
Branch: 1 branch
BranchTrueFalseTotal
exists $meta->{"f_dir_search"} or $meta->{"f_dir_search"} = $dbh->{"f_dir_search"} 50 844 894
855 894 ▶ defined $meta->{f_ext} or $meta->{f_ext} = $dbh->{f_ext};
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{"f_ext"} or $meta->{"f_ext"} = $dbh->{"f_ext"} 716 178 894
856 894 ▶ defined $meta->{f_encoding} or $meta->{f_encoding} = $dbh->{f_encoding};
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{"f_encoding"} or $meta->{"f_encoding"} = $dbh->{"f_encoding"} 32 862 894
857 894 ▶ exists $meta->{f_lock} or $meta->{f_lock} = $dbh->{f_lock};
Branch: 1 branch
BranchTrueFalseTotal
exists $meta->{"f_lock"} or $meta->{"f_lock"} = $dbh->{"f_lock"} 50 844 894
858 894 ▶ exists $meta->{f_lockfile} or $meta->{f_lockfile} = $dbh->{f_lockfile};
Branch: 1 branch
BranchTrueFalseTotal
exists $meta->{"f_lockfile"} or $meta->{"f_lockfile"} = $dbh->{"f_lockfile"} 50 844 894
859 894 ▶ defined $meta->{f_schema} or $meta->{f_schema} = $dbh->{f_schema};
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{"f_schema"} or $meta->{"f_schema"} = $dbh->{"f_schema"} 0 894 894
860  
861 defined $meta->{f_open_file_needed} or
862 894 ▶ $meta->{f_open_file_needed} = $self->can ("open_file") != DBD::File::Table->can ("open_file");
Branch: 1 branch
BranchTrueFalseTotal
defined $meta->{"f_open_file_needed"} or $meta->{"f_open_file_needed"} = $self->can("open_file") != "DBD::File::Table"->can("open_file") 50 844 894
863  
864 defined ($meta->{sql_data_source}) or
865 $meta->{sql_data_source} = _HANDLE ($meta->{f_file})
866 894 ▶ ? "DBD::File::DataSource::Stream"
Branch: 2 branches
BranchTrueFalseTotal
defined $meta->{"sql_data_source"} or $meta->{"sql_data_source"} = _HANDLE($meta->{"f_file"}) ? "DBD::File::DataSource::Stream" : "DBD::File::DataSource::File" 42 852 894
_HANDLE($meta->{'f_file'}) ? : 0 852 852
867 : "DBD::File::DataSource::File";
868 } # bootstrap_table_meta
869  
870 2288 ▶sub get_table_meta ($$$$;$) {
Subroutine get_table_meta: called CC=2 SCAR=6.9
871 2288 my ($self, $dbh, $table, $file_is_table, $respect_case) = @_;
872  
873 2288 my $meta = $self->SUPER::get_table_meta ($dbh, $table, $respect_case, $file_is_table);
874 2252 $table = $meta->{table_name};
875 2252 ▶ return unless $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 128 2124 2252
876  
877 2124 return ($table, $meta);
878 } # get_table_meta
879  
880 448 my %reset_on_modify = (
881 f_file => [ "f_fqfn", "sql_data_source" ],
882 f_dir => "f_fqfn",
883 f_dir_search => [],
884 f_ext => "f_fqfn",
885 f_lockfile => "f_fqfn", # forces new file2table call
886 );
887  
888 448 __PACKAGE__->register_reset_on_modify (\%reset_on_modify);
889  
890 448 my %compat_map = map { $_ => "f_$_" } qw( file ext lock lockfile );
891  
892 448 __PACKAGE__->register_compat_map (\%compat_map);
893  
894 # ====== DBD::File <= 0.40 compat stuff ========================================
895  
896 # compat to 0.38 .. 0.40 API
897 0 ▶sub open_file {
Subroutine open_file: not called CC=1 SCAR=6.9
898 0 my ($className, $meta, $attrs, $flags) = @_;
899  
900 0 return $className->SUPER::open_data ($meta, $attrs, $flags);
901 } # open_file
902  
903 972 ▶sub open_data {
Subroutine open_data: called CC=2 SCAR=7.1
904 972 my ($className, $meta, $attrs, $flags) = @_;
905  
906 # compat to 0.38 .. 0.40 API
907 $meta->{f_open_file_needed}
908 972 ▶ ? $className->open_file ($meta, $attrs, $flags)
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'f_open_file_needed'} ? : 0 972 972
909 : $className->SUPER::open_data ($meta, $attrs, $flags);
910  
911 864 return;
912 } # open_data
913  
914 # ====== SQL::Eval API =========================================================
915  
916 140 ▶sub drop ($) {
Subroutine drop: called CC=3 SCAR=11.0
917 140 my ($self, $data) = @_;
918 140 my $meta = $self->{meta};
919 140 $self->_release_lock($meta);
920 140 ▶ $meta->{f_fqfn} and unlink $meta->{f_fqfn}; # XXX ==> sql_data_source
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"f_fqfn"} and unlink $meta->{"f_fqfn"} 140 0 140
921 140 ▶ $meta->{f_fqln} and unlink $meta->{f_fqln}; # XXX ==> sql_data_source
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"f_fqln"} and unlink $meta->{"f_fqln"} 116 24 140
922 140 delete $data->{Database}{sql_meta}{$self->{table}};
923 140 return 1;
924 } # drop
925  
926 1004 ▶sub _release_lock {
Subroutine _release_lock: called CC=4 SCAR=13.9
927 1004 my ($self, $meta) = @_;
928 # We have to close the file before unlinking it: Some OS'es will
929 # refuse the unlink otherwise.
930 1004 ▶ $meta->{fh} and $meta->{fh}->close ();
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"fh"} and $meta->{"fh"}->close 44 960 1004
931 1004 ▶ $meta->{lockfh} and eval { flock $meta->{lockfh}, 0 };
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"lockfh"} and eval { do { flock $meta->{"lockfh"}, 0 } } 818 186 1004
932 1004 ▶ $meta->{lockfh} and $meta->{lockfh}->close ();
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"lockfh"} and $meta->{"lockfh"}->close 818 186 1004
933 1004 undef $meta->{fh};
934 1004 undef $meta->{lockfh};
935 } # _release_lock
936  
937 0 ▶sub seek ($$$$) {
Subroutine seek: not called CC=7 SCAR=40.3
938 0 my ($self, $data, $pos, $whence) = @_;
939 0 my $meta = $self->{meta};
940 0 ▶ if ($whence == 0 && $pos == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($whence == 0 and $pos == 0) { } 0 0 0
elsif ($whence != 2 or $pos != 0) { } 0 0 0
Condition0%0/3
$whence == 0 and $pos == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$whence == 0 and $pos == 0
$whence == 0 $pos == 0
Truth table0%0/3
A and B
A= $whence == 0B= $pos == 0
ABresult
0X0
100
111
941 0 ▶ $pos = $meta->{first_row_pos} // 0;
Condition0%0/2
$meta->{"first_row_pos"} // 0
l!l
00
MC/DC0%0/1
$meta->{"first_row_pos"} // 0
$meta->{"first_row_pos"}
Truth table0%0/2
A
A= $meta->{"first_row_pos"}
Aresult
11
00
942 }
943 ▶ elsif ($whence != 2 || $pos != 0) {
Condition0%0/3
$whence != 2 or $pos != 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$whence != 2 or $pos != 0
$whence != 2 $pos != 0
Truth table0%0/3
A or B
A= $whence != 2B= $pos != 0
ABresult
1X1
011
000
944 0 croak "Illegal seek position: pos = $pos, whence = $whence";
945 }
946  
947 $meta->{fh}->seek ($pos, $whence) or
948 0 ▶ croak "Error while seeking in " . $meta->{f_fqfn} . ": $!";
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"fh"}->seek($pos, $whence) or croak('Error while seeking in ' . $meta->{"f_fqfn"} . ": $!") 0 0 0
949 } # seek
950  
951 0 ▶sub truncate ($$) {
Subroutine truncate: not called CC=2 SCAR=17.9
952 0 my ($self, $data) = @_;
953 0 my $meta = $self->{meta};
954 $meta->{fh}->truncate ($meta->{fh}->tell ()) or
955 0 ▶ croak "Error while truncating " . $meta->{f_fqfn} . ": $!";
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"fh"}->truncate($meta->{"fh"}->tell) or croak('Error while truncating ' . $meta->{"f_fqfn"} . ": $!") 0 0 0
956 0 return 1;
957 } # truncate
958  
959 864 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
960 864 my $self = shift;
961 864 my $meta = $self->{meta};
962 864 $self->_release_lock($meta);
963  
964 864 $self->SUPER::DESTROY();
965 } # DESTROY
966  
967 448 1;
968  
969 __END__
« blib/lib/DBI/DBD/Metadata.pm ↑ Summary blib/lib/DBI/Gofer/Request.pm »