blib/lib/DBD/SQLite.pm

filter: Statementstmt 94.9% 372 / 392 Branchbran 76.0% 187 / 246 Conditioncond 70.6% 113 / 160 MC/DCmcdc 40.0% 30 / 75 Subroutinesub 93.3% 28 / 30 Podpod 0.0% 0 / 1 totaltotal 80.7% 730 / 904 CC 195 SCAR 33.0
CC
195
Cov
84%
foreign_key_info
46.8
table_info
42.8
statistics_info
31.7
CRAP 27.1
↑ Summary blib/lib/DBD/SQLite/VirtualTable/FileContent.pm »
1 package DBD::SQLite;
2  
3 116 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 116 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 116 ▶use DBI 1.57 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 116 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 116 our $VERSION = '1.78';
9  
10 # sqlite_version cache (set in the XS bootstrap)
11 116 our ($sqlite_version, $sqlite_version_number);
12  
13 # not sure if we still need these...
14 116 our ($err, $errstr);
15  
16 116 XSLoader::load('DBD::SQLite', $VERSION);
17  
18 # New or old API?
19 116 ▶use constant NEWAPI => ($DBI::VERSION >= 1.608);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # global registry of collation functions, initialized with 2 builtins
22 116 our %COLLATION;
23 116 tie %COLLATION, 'DBD::SQLite::_WriteOnceHash';
24 184 ▶$COLLATION{perl} = sub { $_[0] cmp $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
25 116 ▶$COLLATION{perllocale} = sub { use locale; $_[0] cmp $_[1] };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
26  
27 116 our $drh;
28 116 my $methods_are_installed = 0;
29  
30 110 ▶sub driver {
Subroutine driver: called CC=4 SCAR=13.9
Pod undocumented
31 110 ▶ return $drh if $drh;
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::SQLite::drh 0 110 110
32  
33 110 ▶ if (!$methods_are_installed && DBD::SQLite::NEWAPI ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $methods_are_installed and !!1) 110 0 110
Condition50%1/2
not $methods_are_installed and !!1
!ll
0110
MC/DC0%0/1
not $methods_are_installed and !!1
not $methods_are_installed
Truth table50%1/2
not(A)
A= not $methods_are_installed
Aresult
00
11
34 110 DBI->setup_driver('DBD::SQLite');
35  
36 110 DBD::SQLite::db->install_method('sqlite_last_insert_rowid');
37 110 DBD::SQLite::db->install_method('sqlite_busy_timeout');
38 110 DBD::SQLite::db->install_method('sqlite_create_function');
39 110 DBD::SQLite::db->install_method('sqlite_create_aggregate');
40 110 DBD::SQLite::db->install_method('sqlite_create_collation');
41 110 DBD::SQLite::db->install_method('sqlite_collation_needed');
42 110 DBD::SQLite::db->install_method('sqlite_progress_handler');
43 110 DBD::SQLite::db->install_method('sqlite_commit_hook');
44 110 DBD::SQLite::db->install_method('sqlite_rollback_hook');
45 110 DBD::SQLite::db->install_method('sqlite_update_hook');
46 110 DBD::SQLite::db->install_method('sqlite_set_authorizer');
47 110 DBD::SQLite::db->install_method('sqlite_backup_from_file');
48 110 DBD::SQLite::db->install_method('sqlite_backup_to_file');
49 110 DBD::SQLite::db->install_method('sqlite_backup_from_dbh');
50 110 DBD::SQLite::db->install_method('sqlite_backup_to_dbh');
51 110 DBD::SQLite::db->install_method('sqlite_enable_load_extension');
52 110 DBD::SQLite::db->install_method('sqlite_load_extension');
53 110 DBD::SQLite::db->install_method('sqlite_register_fts3_perl_tokenizer');
54 110 DBD::SQLite::db->install_method('sqlite_trace', { O => 0x0004 });
55 110 DBD::SQLite::db->install_method('sqlite_profile', { O => 0x0004 });
56 110 DBD::SQLite::db->install_method('sqlite_table_column_metadata', { O => 0x0004 });
57 110 DBD::SQLite::db->install_method('sqlite_db_filename', { O => 0x0004 });
58 110 DBD::SQLite::db->install_method('sqlite_db_status', { O => 0x0004 });
59 110 DBD::SQLite::st->install_method('sqlite_st_status', { O => 0x0004 });
60 110 DBD::SQLite::db->install_method('sqlite_create_module');
61 110 DBD::SQLite::db->install_method('sqlite_limit');
62 110 DBD::SQLite::db->install_method('sqlite_db_config');
63 110 DBD::SQLite::db->install_method('sqlite_get_autocommit');
64 110 DBD::SQLite::db->install_method('sqlite_txn_state');
65 110 DBD::SQLite::db->install_method('sqlite_error_offset');
66  
67 110 $methods_are_installed++;
68 }
69  
70 110 $drh = DBI::_new_drh( "$_[0]::dr", {
71 Name => 'SQLite',
72 Version => $VERSION,
73 Attribution => 'DBD::SQLite by Matt Sergeant et al',
74 } );
75  
76 110 return $drh;
77 }
78  
79 0 ▶sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
80 0 undef $drh;
81 }
82  
83  
84 package # hide from PAUSE
85 DBD::SQLite::dr;
86  
87 313 ▶sub connect {
Subroutine connect: called CC=14 SCAR=29.9
88 313 my ($drh, $dbname, $user, $auth, $attr) = @_;
89  
90 # Default PrintWarn to the value of $^W
91 # unless ( defined $attr->{PrintWarn} ) {
92 # $attr->{PrintWarn} = $^W ? 1 : 0;
93 # }
94  
95 313 my $dbh = DBI::_new_dbh( $drh, {
96 Name => $dbname,
97 } );
98  
99 313 my $real = $dbname;
100 313 ▶ if ( $dbname =~ /=/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbname =~ /=/) 296 17 313
101 296 foreach my $attrib ( split(/;/, $dbname) ) {
102 298 my ($key, $value) = split(/=/, $attrib, 2);
103 298 ▶ if ( $key =~ /^(?:db(?:name)?|database)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key =~ /^(?:db(?:name)?|database)$/) { } 285 13 298
elsif ($key eq 'uri') { } 6 7 13
104 285 $real = $value;
105 } elsif ( $key eq 'uri' ) {
106 6 $real = $value;
107 6 $attr->{sqlite_open_flags} |= DBD::SQLite::OPEN_URI();
108 } else {
109 7 $attr->{$key} = $value;
110 }
111 }
112 }
113  
114 313 ▶ if (my $flags = $attr->{sqlite_open_flags}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $flags = $attr->{"sqlite_open_flags"}) 19 294 313
115 19 ▶ unless ($flags & (DBD::SQLite::OPEN_READONLY() | DBD::SQLite::OPEN_READWRITE())) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flags & (&DBD::SQLite::OPEN_READONLY() | &DBD::SQLite::OPEN_READWRITE())) 13 6 19
116 13 $attr->{sqlite_open_flags} |= DBD::SQLite::OPEN_READWRITE() | DBD::SQLite::OPEN_CREATE();
117 }
118 }
119  
120 # To avoid unicode and long file name problems on Windows,
121 # convert to the shortname if the file (or parent directory) exists.
122 313 ▶ if ( $^O =~ /MSWin32/ and $real ne ':memory:' and $real ne '' and $real !~ /^file:/ and !-f $real ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /MSWin32/ and $real ne ":memory:" and $real ne "" and not $real =~ /^file:/ and not -f $real) 0 313 313
Condition33%4/12
$^O =~ /MSWin32/ and $real ne ":memory:" and $real ne "" and not $real =~ /^file:/ and not -f $real
!ll&&!rl&&r
31300
$^O =~ /MSWin32/ and $real ne ":memory:" and $real ne "" and not $real =~ /^file:/
!ll&&!rl&&r
31300
$^O =~ /MSWin32/ and $real ne ":memory:" and $real ne ""
!ll&&!rl&&r
31300
$^O =~ /MSWin32/ and $real ne ":memory:"
!ll&&!rl&&r
31300
MC/DC0%0/5
$^O =~ /MSWin32/ and $real ne ":memory:" and $real ne "" and not $real =~ /^file:/ and not -f $real
$^O =~ /MSWin32/ $real ne ":memory:" $real ne "" not $real =~ /^file:/ not -f $real
Truth table16%1/6
A and B and C and not(D) and not(E)
A= $^O =~ /MSWin32/B= $real ne ":memory:"C= $real ne ""D= not $real =~ /^file:/E= not -f $real
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
123 0 require File::Basename;
124 0 my ($file, $dir, $suffix) = File::Basename::fileparse($real);
125 # We are creating a new file.
126 # Does the directory it's in at least exist?
127 0 ▶ if ( -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) { } 0 0 0
128 0 require Win32;
129 0 $real = join '', grep { defined } Win32::GetShortPathName($dir), $file, $suffix;
130 } else {
131 # SQLite can't do mkpath anyway.
132 # So let it go through as it and fail.
133 }
134 }
135  
136 # Hand off to the actual login function
137 313 ▶ DBD::SQLite::db::_login($dbh, $real, $user, $auth, $attr) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
DBD::SQLite::db::_login($dbh, $real, $user, $auth, $attr) or return undef 307 6 313
138  
139 # Register the on-demand collation installer, REGEXP function and
140 # perl tokenizer
141 307 if ( DBD::SQLite::NEWAPI ) {
142 307 $dbh->sqlite_collation_needed( \&install_collation );
143 307 $dbh->sqlite_create_function( "REGEXP", 2, \&regexp );
144 307 $dbh->sqlite_register_fts3_perl_tokenizer();
145 } else {
146 $dbh->func( \&install_collation, "collation_needed" );
147 $dbh->func( "REGEXP", 2, \&regexp, "create_function" );
148 $dbh->func( "register_fts3_perl_tokenizer" );
149 }
150  
151 # HACK: Since PrintWarn = 0 doesn't seem to actually prevent warnings
152 # in DBD::SQLite we set Warn to false if PrintWarn is false.
153  
154 # NOTE: According to the explanation by timbunce,
155 # "Warn is meant to report on bad practices or problems with
156 # the DBI itself (hence always on by default), while PrintWarn
157 # is meant to report warnings coming from the database."
158 # That is, if you want to disable an ineffective rollback warning
159 # etc (due to bad practices), you should turn off Warn,
160 # and to silence other warnings, turn off PrintWarn.
161 # Warn and PrintWarn are independent, and turning off PrintWarn
162 # does not silence those warnings that should be controlled by
163 # Warn.
164  
165 # unless ( $attr->{PrintWarn} ) {
166 # $attr->{Warn} = 0;
167 # }
168  
169 307 return $dbh;
170 }
171  
172 12 ▶sub install_collation {
Subroutine install_collation: called CC=3 SCAR=13.0
173 12 my $dbh = shift;
174 12 my $name = shift;
175 12 my $collation = $DBD::SQLite::COLLATION{$name};
176 12 ▶ unless ($collation) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($collation) 0 12 12
177 0 ▶ warn "Can't install unknown collation: $name" if $dbh->{PrintWarn};
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"PrintWarn"} 0 0 0
178 0 return;
179 }
180 12 if ( DBD::SQLite::NEWAPI ) {
181 12 $dbh->sqlite_create_collation( $name => $collation );
182 } else {
183 $dbh->func( $name => $collation, "create_collation" );
184 }
185 }
186  
187 # default implementation for sqlite 'REGEXP' infix operator.
188 # Note : args are reversed, i.e. "a REGEXP b" calls REGEXP(b, a)
189 # (see https://www.sqlite.org/vtab.html#xfindfunction)
190 392 ▶sub regexp {
Subroutine regexp: called CC=3 SCAR=11.0
191 116 ▶ use locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
192 392 ▶ return if !defined $_[0] || !defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and defined $_[1] 128 264 392
Condition66%2/3
defined $_[0] and defined $_[1]
!ll&&!rl&&r
1280264
MC/DC50%1/2
defined $_[0] and defined $_[1]
defined $_[0] defined $_[1]
Truth table66%2/3
A and B
A= defined $_[0]B= defined $_[1]
ABresult
0X0
100
111
193 264 return scalar($_[1] =~ $_[0]);
194 }
195  
196 package # hide from PAUSE
197 DBD::SQLite::db;
198  
199 116 ▶use DBI qw/:sql_types/;
Subroutine BEGIN: called CC=1 SCAR=0.0
200  
201 1380 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=11.0
202 1380 my $dbh = shift;
203 1380 my $sql = shift;
204 1380 ▶ $sql = '' unless defined $sql;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sql 0 1380 1380
205  
206 1380 my $sth = DBI::_new_sth( $dbh, {
207 Statement => $sql,
208 } );
209  
210 1380 ▶ DBD::SQLite::st::_prepare($sth, $sql, @_) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
DBD::SQLite::st::_prepare($sth, $sql, @_) or return undef 1359 21 1380
211  
212 1359 return $sth;
213 }
214  
215 2979 ▶sub do {
Subroutine do: called CC=11 SCAR=24.0
216 2979 my ($dbh, $statement, $attr, @bind_values) = @_;
217  
218 # shortcut
219 2979 my $allow_multiple_statements = $dbh->FETCH('sqlite_allow_multiple_statements');
220 2979 ▶ if (defined $statement && !defined $attr && !@bind_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $statement and not defined $attr and not @bind_values) 2871 108 2979
Condition100%6/6
defined $statement and not defined $attr and not @bind_values
!ll&&!rl&&r
42662871
defined $statement and not defined $attr
!ll&&!rl&&r
1412937
MC/DC100%3/3
defined $statement and not defined $attr and not @bind_values
defined $statement not defined $attr not @bind_values
Truth table100%4/4
A and not(B) and not(C)
A= defined $statementB= not defined $attrC= not @bind_values
ABCresult
0XX0
10X0
1100
1111
221 # _do() (i.e. sqlite3_exec()) runs semicolon-separate SQL
222 # statements, which is handy but insecure sometimes.
223 # Use this only when it's safe or explicitly allowed.
224 2871 ▶ if (index($statement, ';') == -1 or $allow_multiple_statements) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($statement, ";") == -1 or $allow_multiple_statements) 2848 23 2871
Condition66%2/3
index($statement, ";") == -1 or $allow_multiple_statements
l!l&&r!l&&!r
2848023
MC/DC50%1/2
index($statement, ";") == -1 or $allow_multiple_statements
index($statement, ";") == -1 $allow_multiple_statements
Truth table66%2/3
A or B
A= index($statement, ";") == -1B= $allow_multiple_statements
ABresult
1X1
011
000
225 2848 return DBD::SQLite::db::_do($dbh, $statement);
226 }
227 }
228  
229 131 my @copy = @{[@bind_values]};
230 131 my $rows = 0;
231  
232 131 ▶ while ($statement) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement) 136 3 139
233 136 ▶ my $sth = $dbh->prepare($statement, $attr) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($statement, $attr) or return undef 123 13 136
234 123 ▶ $sth->execute(splice @copy, 0, $sth->{NUM_OF_PARAMS}) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(splice(@copy, 0, $sth->{"NUM_OF_PARAMS"})) or return undef 119 4 123
235 119 $rows += $sth->rows;
236 # XXX: not sure why but $dbh->{sqlite...} wouldn't work here
237 119 ▶ last unless $allow_multiple_statements;
Branch: 1 branch
BranchTrueFalseTotal
unless $allow_multiple_statements 111 8 119
238 8 $statement = $sth->{sqlite_unprepared_statements};
239 }
240  
241 # always return true if no error
242 114 ▶ return ($rows == 0) ? "0E0" : $rows;
Branch: 1 branch
BranchTrueFalseTotal
$rows == 0 ? : 16 98 114
243 }
244  
245 1 ▶sub ping {
Subroutine ping: called CC=4 SCAR=15.6
246 1 my $dbh = shift;
247  
248 # $file may be undef (ie. in-memory/temporary database)
249 1 my $file = DBD::SQLite::NEWAPI ? $dbh->sqlite_db_filename
250 : $dbh->func("db_filename");
251  
252 1 ▶ return 0 if $file && !-f $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file and not -f $file 0 1 1
Condition33%1/3
$file and not -f $file
!ll&&!rl&&r
100
MC/DC0%0/2
$file and not -f $file
$file not -f $file
Truth table33%1/3
A and not(B)
A= $fileB= not -f $file
ABresult
0X0
100
111
253 1 ▶ return $dbh->FETCH('Active') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->FETCH('Active') ? : 1 0 1
254 }
255  
256 8 ▶sub quote {
Subroutine quote: called CC=8 SCAR=20.8
257 8 my ($self, $value, $data_type) = @_;
258 8 ▶ return "NULL" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 7 8
259 7 ▶ if (defined $data_type and (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data_type and $data_type == &DBI::SQL_BIT() || $data_type == &DBI::SQL_BLOB() || $data_type == &DBI::SQL_BINARY() || $data_type == &DBI::SQL_VARBINARY() || $data_type == &DBI::SQL_LONGVARBINARY()) 6 1 7
Condition86%13/15
defined $data_type and $data_type == &DBI::SQL_BIT() || $data_type == &DBI::SQL_BLOB() || $data_type == &DBI::SQL_BINARY() || $data_type == &DBI::SQL_VARBINARY() || $data_type == &DBI::SQL_LONGVARBINARY()
!ll&&!rl&&r
106
$data_type == &DBI::SQL_BIT() or $data_type == &DBI::SQL_BLOB() or $data_type == &DBI::SQL_BINARY() or $data_type == &DBI::SQL_VARBINARY() or $data_type == &DBI::SQL_LONGVARBINARY()
l!l&&r!l&&!r
510
$data_type == &DBI::SQL_BIT() or $data_type == &DBI::SQL_BLOB() or $data_type == &DBI::SQL_BINARY() or $data_type == &DBI::SQL_VARBINARY()
l!l&&r!l&&!r
411
$data_type == &DBI::SQL_BIT() or $data_type == &DBI::SQL_BLOB() or $data_type == &DBI::SQL_BINARY()
l!l&&r!l&&!r
312
$data_type == &DBI::SQL_BIT() or $data_type == &DBI::SQL_BLOB()
l!l&&r!l&&!r
123
MC/DC16%1/6
defined $data_type and $data_type == &DBI::SQL_BIT() || $data_type == &DBI::SQL_BLOB() || $data_type == &DBI::SQL_BINARY() || $data_type == &DBI::SQL_VARBINARY() || $data_type == &DBI::SQL_LONGVARBINARY()
defined $data_type $data_type == &DBI::SQL_BIT() $data_type == &DBI::SQL_BLOB() $data_type == &DBI::SQL_BINARY() $data_type == &DBI::SQL_VARBINARY() $data_type == &DBI::SQL_LONGVARBINARY()
Truth table85%6/7
A and B or C or D or E or F
A= defined $data_typeB= $data_type == &DBI::SQL_BIT()C= $data_type == &DBI::SQL_BLOB()D= $data_type == &DBI::SQL_BINARY()E= $data_type == &DBI::SQL_VARBINARY()F= $data_type == &DBI::SQL_LONGVARBINARY()
ABCDEFresult
0XXXXX0
1000000
11XXXX1
101XXX1
1001XX1
10001X1
1000011
260 $data_type == DBI::SQL_BIT ||
261 $data_type == DBI::SQL_BLOB ||
262 $data_type == DBI::SQL_BINARY ||
263 $data_type == DBI::SQL_VARBINARY ||
264 $data_type == DBI::SQL_LONGVARBINARY)) {
265 6 return q(X') . unpack('H*', $value) . q(');
266 }
267 1 $value =~ s/'/''/g;
268 1 return "'$value'";
269 }
270  
271 79 ▶sub get_info {
Subroutine get_info: called CC=2 SCAR=6.9
272 79 my ($dbh, $info_type) = @_;
273  
274 79 require DBD::SQLite::GetInfo;
275 79 my $v = $DBD::SQLite::GetInfo::info{int($info_type)};
276 79 ▶ $v = $v->($dbh) if ref $v eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "CODE" 6 73 79
277 79 return $v;
278 }
279  
280 21 ▶sub _attached_database_list {
Subroutine _attached_database_list: called CC=5 SCAR=16.2
281 21 my $dbh = shift;
282 21 my @attached;
283  
284 21 ▶ my $sth_databases = $dbh->prepare( 'PRAGMA database_list' ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth_databases = $dbh->prepare("PRAGMA database_list") or return 21 0 21
285 21 ▶ $sth_databases->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth_databases->execute or return 21 0 21
286 21 ▶ while ( my $db_info = $sth_databases->fetchrow_hashref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $db_info = $sth_databases->fetchrow_hashref) 47 21 68
287 47 ▶ push @attached, $db_info->{name} if $db_info->{seq} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $db_info->{"seq"} >= 2 11 36 47
288 }
289 21 return @attached;
290 }
291  
292 # SQL/CLI (ISO/IEC JTC 1/SC 32 N 0595), 6.63 Tables
293 # Based on DBD::Oracle's
294 # See also http://www.ch-werner.de/sqliteodbc/html/sqlite3odbc_8c.html#a213
295 16 ▶sub table_info {
Subroutine table_info: called CC=34 SCAR=37.6
296 16 my ($dbh, $cat_val, $sch_val, $tbl_val, $typ_val, $attr) = @_;
297  
298 16 my @where = ();
299 16 my $sql;
300 16 ▶ if ( defined($cat_val) && $cat_val eq '%'
Branch: 3 branches
BranchTrueFalseTotal
if (defined $cat_val and $cat_val eq '%' and defined $sch_val and $sch_val eq '' and defined $tbl_val and $tbl_val eq '') { } 1 15 16
elsif (defined $cat_val and $cat_val eq '' and defined $sch_val and $sch_val eq '%' and defined $tbl_val and $tbl_val eq '') { } 1 14 15
elsif (defined $cat_val and $cat_val eq '' and defined $sch_val and $sch_val eq '' and defined $tbl_val and $tbl_val eq '' and defined $typ_val and $typ_val eq '%') { } 1 13 14
Condition73%11/15
defined $cat_val and $cat_val eq "%" and defined $sch_val and $sch_val eq "" and defined $tbl_val and $tbl_val eq ""
!ll&&!rl&&r
1501
defined $cat_val and $cat_val eq "%" and defined $sch_val and $sch_val eq "" and defined $tbl_val
!ll&&!rl&&r
1501
defined $cat_val and $cat_val eq "%" and defined $sch_val and $sch_val eq ""
!ll&&!rl&&r
1501
defined $cat_val and $cat_val eq "%" and defined $sch_val
!ll&&!rl&&r
1501
defined $cat_val and $cat_val eq "%"
!ll&&!rl&&r
1321
MC/DC33%2/6
defined $cat_val and $cat_val eq "%" and defined $sch_val and $sch_val eq "" and defined $tbl_val and $tbl_val eq ""
defined $cat_val $cat_val eq "%" defined $sch_val $sch_val eq "" defined $tbl_val $tbl_val eq ""
Truth table42%3/7
A and B and C and D and E and F
A= defined $cat_valB= $cat_val eq "%"C= defined $sch_valD= $sch_val eq ""E= defined $tbl_valF= $tbl_val eq ""
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
301 && defined($sch_val) && $sch_val eq ''
302 && defined($tbl_val) && $tbl_val eq '') { # Rule 19a
303 1 $sql = <<'END_SQL';
304 SELECT NULL TABLE_CAT
305 , NULL TABLE_SCHEM
306 , NULL TABLE_NAME
307 , NULL TABLE_TYPE
308 , NULL REMARKS
309 END_SQL
310 }
311 ▶ elsif ( defined($cat_val) && $cat_val eq ''
Condition73%11/15
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "%" and defined $tbl_val and $tbl_val eq ""
!ll&&!rl&&r
1401
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "%" and defined $tbl_val
!ll&&!rl&&r
1401
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "%"
!ll&&!rl&&r
1311
defined $cat_val and $cat_val eq "" and defined $sch_val
!ll&&!rl&&r
1302
defined $cat_val and $cat_val eq ""
!ll&&!rl&&r
1302
MC/DC33%2/6
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "%" and defined $tbl_val and $tbl_val eq ""
defined $cat_val $cat_val eq "" defined $sch_val $sch_val eq "%" defined $tbl_val $tbl_val eq ""
Truth table42%3/7
A and B and C and D and E and F
A= defined $cat_valB= $cat_val eq ""C= defined $sch_valD= $sch_val eq "%"E= defined $tbl_valF= $tbl_val eq ""
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
312 && defined($sch_val) && $sch_val eq '%'
313 && defined($tbl_val) && $tbl_val eq '') { # Rule 19b
314 1 $sql = <<'END_SQL';
315 SELECT NULL TABLE_CAT
316 , t.tn TABLE_SCHEM
317 , NULL TABLE_NAME
318 , NULL TABLE_TYPE
319 , NULL REMARKS
320 FROM (
321 SELECT 'main' tn
322 UNION SELECT 'temp' tn
323 END_SQL
324 1 for my $db_name (_attached_database_list($dbh)) {
325 0 $sql .= " UNION SELECT '$db_name' tn\n";
326 }
327 1 $sql .= ") t\n";
328 }
329 ▶ elsif ( defined($cat_val) && $cat_val eq ''
Condition66%14/21
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "" and defined $tbl_val and $tbl_val eq "" and defined $typ_val and $typ_val eq "%"
!ll&&!rl&&r
1301
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "" and defined $tbl_val and $tbl_val eq "" and defined $typ_val
!ll&&!rl&&r
1301
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "" and defined $tbl_val and $tbl_val eq ""
!ll&&!rl&&r
1301
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "" and defined $tbl_val
!ll&&!rl&&r
1301
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq ""
!ll&&!rl&&r
1301
defined $cat_val and $cat_val eq "" and defined $sch_val
!ll&&!rl&&r
1301
defined $cat_val and $cat_val eq ""
!ll&&!rl&&r
1301
MC/DC12%1/8
defined $cat_val and $cat_val eq "" and defined $sch_val and $sch_val eq "" and defined $tbl_val and $tbl_val eq "" and defined $typ_val and $typ_val eq "%"
defined $cat_val $cat_val eq "" defined $sch_val $sch_val eq "" defined $tbl_val $tbl_val eq "" defined $typ_val $typ_val eq "%"
Truth table22%2/9
A and B and C and D and E and F and G and H
A= defined $cat_valB= $cat_val eq ""C= defined $sch_valD= $sch_val eq ""E= defined $tbl_valF= $tbl_val eq ""G= defined $typ_valH= $typ_val eq "%"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
330 && defined($sch_val) && $sch_val eq ''
331 && defined($tbl_val) && $tbl_val eq ''
332 && defined($typ_val) && $typ_val eq '%') { # Rule 19c
333 1 $sql = <<'END_SQL';
334 SELECT NULL TABLE_CAT
335 , NULL TABLE_SCHEM
336 , NULL TABLE_NAME
337 , t.tt TABLE_TYPE
338 , NULL REMARKS
339 FROM (
340 SELECT 'TABLE' tt UNION
341 SELECT 'VIEW' tt UNION
342 SELECT 'LOCAL TEMPORARY' tt UNION
343 SELECT 'SYSTEM TABLE' tt
344 ) t
345 ORDER BY TABLE_TYPE
346 END_SQL
347 }
348 else {
349 13 $sql = <<'END_SQL';
350 SELECT *
351 FROM
352 (
353 SELECT NULL TABLE_CAT
354 , TABLE_SCHEM
355 , tbl_name TABLE_NAME
356 , TABLE_TYPE
357 , NULL REMARKS
358 , sql sqlite_sql
359 FROM (
360 SELECT 'main' TABLE_SCHEM, tbl_name, upper(type) TABLE_TYPE, sql
361 FROM sqlite_master
362 UNION ALL
363 SELECT 'temp' TABLE_SCHEM, tbl_name, 'LOCAL TEMPORARY' TABLE_TYPE, sql
364 FROM sqlite_temp_master
365 END_SQL
366  
367 13 for my $db_name (_attached_database_list($dbh)) {
368 9 $sql .= <<"END_SQL";
369 UNION ALL
370 SELECT '$db_name' TABLE_SCHEM, tbl_name, upper(type) TABLE_TYPE, sql
371 FROM "$db_name".sqlite_master
372 END_SQL
373 }
374  
375 13 $sql .= <<'END_SQL';
376 UNION ALL
377 SELECT 'main' TABLE_SCHEM, 'sqlite_master' tbl_name, 'SYSTEM TABLE' TABLE_TYPE, NULL sql
378 UNION ALL
379 SELECT 'temp' TABLE_SCHEM, 'sqlite_temp_master' tbl_name, 'SYSTEM TABLE' TABLE_TYPE, NULL sql
380 )
381 )
382 END_SQL
383 13 ▶ $attr = {} unless ref $attr eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attr eq "HASH" 13 0 13
384 13 ▶ my $escape = defined $attr->{Escape} ? " ESCAPE '$attr->{Escape}'" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $attr->{'Escape'} ? : 0 13 13
385 13 ▶ if ( defined $sch_val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sch_val) 3 10 13
386 3 push @where, "TABLE_SCHEM LIKE '$sch_val'$escape";
387 }
388 13 ▶ if ( defined $tbl_val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tbl_val) 11 2 13
389 11 push @where, "TABLE_NAME LIKE '$tbl_val'$escape";
390 }
391 13 ▶ if ( defined $typ_val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $typ_val) 1 12 13
392 1 my $table_type_list;
393 1 $typ_val =~ s/^\s+//;
394 1 $typ_val =~ s/\s+$//;
395 1 my @ttype_list = split (/\s*,\s*/, $typ_val);
396 1 foreach my $table_type (@ttype_list) {
397 1 ▶ if ($table_type !~ /^'.*'$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_type =~ /^'.*'$/) 1 0 1
398 1 $table_type = "'" . $table_type . "'";
399 }
400 }
401 1 $table_type_list = join(', ', @ttype_list);
402 1 ▶ push @where, "TABLE_TYPE IN (\U$table_type_list)" if $table_type_list;
Branch: 1 branch
BranchTrueFalseTotal
if $table_type_list 1 0 1
403 }
404 13 ▶ $sql .= ' WHERE ' . join("\n AND ", @where ) . "\n" if @where;
Branch: 1 branch
BranchTrueFalseTotal
if @where 12 1 13
405 13 $sql .= " ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME\n";
406 }
407 16 ▶ my $sth = $dbh->prepare($sql) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return undef 16 0 16
408 16 ▶ $sth->execute or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return undef 16 0 16
409 16 $sth;
410 }
411  
412 33 ▶sub primary_key_info {
Subroutine primary_key_info: called CC=26 SCAR=32.8
413 33 my ($dbh, $catalog, $schema, $table, $attr) = @_;
414  
415 33 my $databases = $dbh->selectall_arrayref("PRAGMA database_list", {Slice => {}});
416  
417 33 my @pk_info;
418 33 for my $database (@$databases) {
419 49 my $dbname = $database->{name};
420 49 ▶ next if defined $schema && $schema ne '%' && $schema ne $dbname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema and $schema ne "%" and $schema ne $dbname 6 43 49
Condition83%5/6
defined $schema and $schema ne "%" and $schema ne $dbname
!ll&&!rl&&r
4036
defined $schema and $schema ne "%"
!ll&&!rl&&r
4009
MC/DC66%2/3
defined $schema and $schema ne "%" and $schema ne $dbname
defined $schema $schema ne "%" $schema ne $dbname
Truth table75%3/4
A and B and C
A= defined $schemaB= $schema ne "%"C= $schema ne $dbname
ABCresult
0XX0
10X0
1100
1111
421  
422 43 my $quoted_dbname = $dbh->quote_identifier($dbname);
423  
424 43 ▶ my $master_table =
Branch: 2 branches
BranchTrueFalseTotal
$dbname eq 'main' ? : 31 12 43
$dbname eq 'temp' ? : 8 4 12
425 ($dbname eq 'main') ? 'sqlite_master' :
426 ($dbname eq 'temp') ? 'sqlite_temp_master' :
427 $quoted_dbname.'.sqlite_master';
428  
429 43 ▶ my $sth = $dbh->prepare("SELECT name, sql FROM $master_table WHERE type = ?") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare("SELECT name, sql FROM $master_table WHERE type = ?") or return 43 0 43
430 43 ▶ $sth->execute("table") or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute("table") or return 43 0 43
431 43 ▶ while(my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 55 43 98
432 55 my $tbname = $row->{name};
433 55 ▶ next if defined $table && $table ne '%' && $table ne $tbname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $table and $table ne "%" and $table ne $tbname 22 33 55
Condition83%5/6
defined $table and $table ne "%" and $table ne $tbname
!ll&&!rl&&r
33022
defined $table and $table ne "%"
!ll&&!rl&&r
3052
MC/DC66%2/3
defined $table and $table ne "%" and $table ne $tbname
defined $table $table ne "%" $table ne $tbname
Truth table75%3/4
A and B and C
A= defined $tableB= $table ne "%"C= $table ne $tbname
ABCresult
0XX0
10X0
1100
1111
434  
435 33 my $quoted_tbname = $dbh->quote_identifier($tbname);
436 33 ▶ my $t_sth = $dbh->prepare("PRAGMA $quoted_dbname.table_xinfo($quoted_tbname)") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $t_sth = $dbh->prepare("PRAGMA $quoted_dbname.table_xinfo($quoted_tbname)") or return 33 0 33
437 33 ▶ $t_sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$t_sth->execute or return 33 0 33
438 33 my @pk;
439 33 ▶ while(my $col = $t_sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = $t_sth->fetchrow_hashref) 52 33 85
440 52 ▶ push @pk, $col->{name} if $col->{pk};
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"pk"} 38 14 52
441 }
442  
443 # If there're multiple primary key columns, we need to
444 # find their order from one of the auto-generated unique
445 # indices (note that single column integer primary key
446 # doesn't create an index).
447 33 ▶ if (@pk > 1 and $row->{sql} =~ /\bPRIMARY\s+KEY\s*\(\s*
Branch: 1 branch
BranchTrueFalseTotal
if (@pk > 1 and $row->{"sql"} =~ /\bPRIMARY\s+KEY\s*\(\s* ( (?: ( [a-z_][a-z0-9_]* | (["'`])(?:\3\3|(?!\3).)+?\3(?!\3) | \[[^\]]+\] ) \s*,\s* )+ ( [a-z_][a-z0-9_]* | (["'`])(?:\5\5|(?!\5).)+?\5(?!\5) | \[[^\]]+\] ) ) \s*\)/six) 4 29 33
Condition66%2/3
@pk > 1 and $row->{"sql"} =~ /\bPRIMARY\s+KEY\s*\(\s* ( (?: ( [a-z_][a-z0-9_]* | (["'`])(?:\3\3|(?!\3).)+?\3(?!\3) | \[[^\]]+\] ) \s*,\s* )+ ( [a-z_][a-z0-9_]* | (["'`])(?:\5\5|(?!\5).)+?\5(?!\5) | \[[^\]]+\] ) ) \s*\)/six
!ll&&!rl&&r
2904
MC/DC50%1/2
@pk > 1 and $row->{"sql"} =~ /\bPRIMARY\s+KEY\s*\(\s* ( (?: ( [a-z_][a-z0-9_]* | (["'`])(?:\3\3|(?!\3).)+?\3(?!\3) | \[[^\]]+\] ) \s*,\s* )+ ( [a-z_][a-z0-9_]* | (["'`])(?:\5\5|(?!\5).)+?\5(?!\5) | \[[^\]]+\] ) ) \s*\)/six
@pk > 1 $row->{"sql"} =~ /\bPRIMARY\s+KEY\s*\(\s* ( (?: ( [a-z_][a-z0-9_]* | (["'`])(?:\3\3|(?!\3).)+?\3(?!\3) | \[[^\]]+\] ) \s*,\s* )+ ( [a-z_][a-z0-9_]* | (["'`])(?:\5\5|(?!\5).)+?\5(?!\5) | \[[^\]]+\] ) ) \s*\)/six
Truth table66%2/3
A and B
A= @pk > 1B= $row->{"sql"} =~ /\bPRIMARY\s+KEY\s*\(\s* ( (?: ( [a-z_][a-z0-9_]* | (["'`])(?:\3\3|(?!\3).)+?\3(?!\3) | \[[^\]]+\] ) \s*,\s* )+ ( [a-z_][a-z0-9_]* | (["'`])(?:\5\5|(?!\5).)+?\5(?!\5) | \[[^\]]+\] ) ) \s*\)/six
ABresult
0X0
100
111
448 (
449 (?:
450 (
451 [a-z_][a-z0-9_]*
452 | (["'`])(?:\3\3|(?!\3).)+?\3(?!\3)
453 | \[[^\]]+\]
454 )
455 \s*,\s*
456 )+
457 (
458 [a-z_][a-z0-9_]*
459 | (["'`])(?:\5\5|(?!\5).)+?\5(?!\5)
460 | \[[^\]]+\]
461 )
462 )
463 \s*\)/six) {
464 4 my $pk_sql = $1;
465 4 @pk = ();
466 4 ▶ while($pk_sql =~ /
Branch: 1 branch
BranchTrueFalseTotal
if ($pk_sql =~ / ( [a-z_][a-z0-9_]* | (["'`])(?:\2\2|(?!\2).)+?\2(?!\2) | \[([^\]]+)\] ) (?:\s*,\s*|$) /gisx) 9 4 13
467 (
468 [a-z_][a-z0-9_]*
469 | (["'`])(?:\2\2|(?!\2).)+?\2(?!\2)
470 | \[([^\]]+)\]
471 )
472 (?:\s*,\s*|$)
473 /sixg) {
474 9 my($col, $quote, $brack) = ($1, $2, $3);
475 9 ▶ if ( defined $quote ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $quote) { } 2 7 9
elsif (defined $brack) { } 1 6 7
476 # Dequote "'`
477 2 $col = substr $col, 1, -1;
478 2 $col =~ s/$quote$quote/$quote/g;
479 } elsif ( defined $brack ) {
480 # Dequote []
481 1 $col = $brack;
482 }
483 9 push @pk, $col;
484 }
485 }
486  
487 33 ▶ my $key_name = $row->{sql} =~ /\bCONSTRAINT\s+(\S+|"[^"]+")\s+PRIMARY\s+KEY\s*\(/i ? $1 : 'PRIMARY KEY';
Branch: 1 branch
BranchTrueFalseTotal
$row->{'sql'} =~ /\bCONSTRAINT\s+(\S+|"[^"]+")\s+PRIMARY\s+KEY\s*\(/i ? : 1 32 33
488 33 my $key_seq = 0;
489 33 foreach my $pk_field (@pk) {
490 38 push @pk_info, {
491 TABLE_SCHEM => $dbname,
492 TABLE_NAME => $tbname,
493 COLUMN_NAME => $pk_field,
494 KEY_SEQ => ++$key_seq,
495 PK_NAME => $key_name,
496 };
497 }
498 }
499 }
500  
501 33 ▶ my $sponge = DBI->connect("DBI:Sponge:", '','')
Branch: 1 branch
BranchTrueFalseTotal
my $sponge = "DBI"->connect("DBI:Sponge:", "", "") or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr") 33 0 33
502 or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr");
503 33 my @names = qw(TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME KEY_SEQ PK_NAME);
504 my $sth = $sponge->prepare( "primary_key_info", {
505 33 ▶ rows => [ map { [ @{$_}{@names} ] } @pk_info ],
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $sponge->prepare("primary_key_info", {"rows", [map({[@{$_;}{@names}];} @pk_info)], "NUM_OF_FIELDS", scalar @names, "NAME", \@names}) or return $dbh->DBI::set_err($sponge->err, $sponge->errstr) 33 0 33
506 NUM_OF_FIELDS => scalar @names,
507 NAME => \@names,
508 }) or return $dbh->DBI::set_err(
509 $sponge->err,
510 $sponge->errstr,
511 );
512 33 return $sth;
513 }
514  
515  
516 116 our %DBI_code_for_rule = ( # from DBI doc; curiously, they are not exported
517 # by the DBI module.
518 # codes for update/delete constraints
519 'CASCADE' => 0,
520 'RESTRICT' => 1,
521 'SET NULL' => 2,
522 'NO ACTION' => 3,
523 'SET DEFAULT' => 4,
524  
525 # codes for deferrability
526 'INITIALLY DEFERRED' => 5,
527 'INITIALLY IMMEDIATE' => 6,
528 'NOT DEFERRABLE' => 7,
529 );
530  
531  
532 116 my @FOREIGN_KEY_INFO_ODBC = (
533 'PKTABLE_CAT', # The primary (unique) key table catalog identifier.
534 'PKTABLE_SCHEM', # The primary (unique) key table schema identifier.
535 'PKTABLE_NAME', # The primary (unique) key table identifier.
536 'PKCOLUMN_NAME', # The primary (unique) key column identifier.
537 'FKTABLE_CAT', # The foreign key table catalog identifier.
538 'FKTABLE_SCHEM', # The foreign key table schema identifier.
539 'FKTABLE_NAME', # The foreign key table identifier.
540 'FKCOLUMN_NAME', # The foreign key column identifier.
541 'KEY_SEQ', # The column sequence number (starting with 1).
542 'UPDATE_RULE', # The referential action for the UPDATE rule.
543 'DELETE_RULE', # The referential action for the DELETE rule.
544 'FK_NAME', # The foreign key name.
545 'PK_NAME', # The primary (unique) key name.
546 'DEFERRABILITY', # The deferrability of the foreign key constraint.
547 'UNIQUE_OR_PRIMARY', # qualifies the key referenced by the foreign key
548 );
549  
550 # Column names below are not used, but listed just for completeness's sake.
551 # Maybe we could add an option so that the user can choose which field
552 # names will be returned; the DBI spec is not very clear about ODBC vs. CLI.
553 116 my @FOREIGN_KEY_INFO_SQL_CLI = qw(
554 UK_TABLE_CAT
555 UK_TABLE_SCHEM
556 UK_TABLE_NAME
557 UK_COLUMN_NAME
558 FK_TABLE_CAT
559 FK_TABLE_SCHEM
560 FK_TABLE_NAME
561 FK_COLUMN_NAME
562 ORDINAL_POSITION
563 UPDATE_RULE
564 DELETE_RULE
565 FK_NAME
566 UK_NAME
567 DEFERABILITY
568 UNIQUE_OR_PRIMARY
569 );
570  
571 116 my $DEFERRABLE_RE = qr/
572 (?:(?:
573 on \s+ (?:delete|update) \s+ (?:set \s+ null|set \s+ default|cascade|restrict|no \s+ action)
574 |
575 match \s* (?:\S+|".+?(?<!")")
576 ) \s*)*
577 ((?:not)? \s* deferrable (?: \s* initially \s* (?: immediate | deferred))?)?
578 /sxi;
579  
580 10 ▶sub foreign_key_info {
Subroutine foreign_key_info: called CC=43 SCAR=38.4
581 10 my ($dbh, $pk_catalog, $pk_schema, $pk_table, $fk_catalog, $fk_schema, $fk_table) = @_;
582  
583 10 ▶ my $databases = $dbh->selectall_arrayref("PRAGMA database_list", {Slice => {}}) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $databases = $dbh->selectall_arrayref("PRAGMA database_list", {"Slice", {}}) or return 10 0 10
584  
585 10 my @fk_info;
586 my %table_info;
587 10 for my $database (@$databases) {
588 20 my $dbname = $database->{name};
589 20 ▶ next if defined $fk_schema && $fk_schema ne '%' && $fk_schema ne $dbname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fk_schema and $fk_schema ne "%" and $fk_schema ne $dbname 1 19 20
Condition83%5/6
defined $fk_schema and $fk_schema ne "%" and $fk_schema ne $dbname
!ll&&!rl&&r
1811
defined $fk_schema and $fk_schema ne "%"
!ll&&!rl&&r
1802
MC/DC66%2/3
defined $fk_schema and $fk_schema ne "%" and $fk_schema ne $dbname
defined $fk_schema $fk_schema ne "%" $fk_schema ne $dbname
Truth table75%3/4
A and B and C
A= defined $fk_schemaB= $fk_schema ne "%"C= $fk_schema ne $dbname
ABCresult
0XX0
10X0
1100
1111
590  
591 19 my $quoted_dbname = $dbh->quote_identifier($dbname);
592 19 ▶ my $master_table =
Branch: 2 branches
BranchTrueFalseTotal
$dbname eq 'main' ? : 9 10 19
$dbname eq 'temp' ? : 4 6 10
593 ($dbname eq 'main') ? 'sqlite_master' :
594 ($dbname eq 'temp') ? 'sqlite_temp_master' :
595 $quoted_dbname.'.sqlite_master';
596  
597 19 ▶ my $tables = $dbh->selectall_arrayref("SELECT name, sql FROM $master_table WHERE type = ?", undef, "table") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tables = $dbh->selectall_arrayref("SELECT name, sql FROM $master_table WHERE type = ?", undef, "table") or return 19 0 19
598 19 for my $table (@$tables) {
599 34 my $tbname = $table->[0];
600 34 my $ddl = $table->[1];
601 34 my (@rels, %relid2rels);
602 34 ▶ next if defined $fk_table && $fk_table ne '%' && $fk_table ne $tbname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fk_table and $fk_table ne "%" and $fk_table ne $tbname 20 14 34
Condition83%5/6
defined $fk_table and $fk_table ne "%" and $fk_table ne $tbname
!ll&&!rl&&r
6820
defined $fk_table and $fk_table ne "%"
!ll&&!rl&&r
6028
MC/DC66%2/3
defined $fk_table and $fk_table ne "%" and $fk_table ne $tbname
defined $fk_table $fk_table ne "%" $fk_table ne $tbname
Truth table75%3/4
A and B and C
A= defined $fk_tableB= $fk_table ne "%"C= $fk_table ne $tbname
ABCresult
0XX0
10X0
1100
1111
603  
604 14 my $quoted_tbname = $dbh->quote_identifier($tbname);
605 14 ▶ my $sth = $dbh->prepare("PRAGMA $quoted_dbname.foreign_key_list($quoted_tbname)") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare("PRAGMA $quoted_dbname.foreign_key_list($quoted_tbname)") or return 14 0 14
606 14 ▶ $sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return 14 0 14
607 14 ▶ while(my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 18 14 32
608 18 ▶ next if defined $pk_table && $pk_table ne '%' && $pk_table ne $row->{table};
Branch: 1 branch
BranchTrueFalseTotal
if defined $pk_table and $pk_table ne "%" and $pk_table ne $row->{"table"} 3 15 18
Condition83%5/6
defined $pk_table and $pk_table ne "%" and $pk_table ne $row->{"table"}
!ll&&!rl&&r
1053
defined $pk_table and $pk_table ne "%"
!ll&&!rl&&r
1008
MC/DC66%2/3
defined $pk_table and $pk_table ne "%" and $pk_table ne $row->{"table"}
defined $pk_table $pk_table ne "%" $pk_table ne $row->{"table"}
Truth table75%3/4
A and B and C
A= defined $pk_tableB= $pk_table ne "%"C= $pk_table ne $row->{"table"}
ABCresult
0XX0
10X0
1100
1111
609  
610 15 ▶ unless ($table_info{$row->{table}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_info{$row->{"table"}}) 13 2 15
611 13 my $quoted_tb = $dbh->quote_identifier($row->{table});
612 13 for my $db (@$databases) {
613 15 my $quoted_db = $dbh->quote_identifier($db->{name});
614 15 ▶ my $t_sth = $dbh->prepare("PRAGMA $quoted_db.table_xinfo($quoted_tb)") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $t_sth = $dbh->prepare("PRAGMA $quoted_db.table_xinfo($quoted_tb)") or return 15 0 15
615 15 ▶ $t_sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$t_sth->execute or return 15 0 15
616 15 my $cols = {};
617 15 ▶ while(my $r = $t_sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $t_sth->fetchrow_hashref) 30 15 45
618 30 $cols->{$r->{name}} = $r->{pk};
619 }
620 15 ▶ if (keys %$cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$cols) 13 2 15
621 $table_info{$row->{table}} = {
622 schema => $db->{name},
623 13 columns => $cols,
624 };
625 13 last;
626 }
627 }
628 }
629  
630 15 ▶ next if defined $pk_schema && $pk_schema ne '%' && $pk_schema ne $table_info{$row->{table}}{schema};
Branch: 1 branch
BranchTrueFalseTotal
if defined $pk_schema and $pk_schema ne "%" and $pk_schema ne $table_info{$row->{"table"}}{"schema"} 2 13 15
Condition83%5/6
defined $pk_schema and $pk_schema ne "%" and $pk_schema ne $table_info{$row->{"table"}}{"schema"}
!ll&&!rl&&r
1122
defined $pk_schema and $pk_schema ne "%"
!ll&&!rl&&r
1104
MC/DC66%2/3
defined $pk_schema and $pk_schema ne "%" and $pk_schema ne $table_info{$row->{"table"}}{"schema"}
defined $pk_schema $pk_schema ne "%" $pk_schema ne $table_info{$row->{"table"}}{"schema"}
Truth table75%3/4
A and B and C
A= defined $pk_schemaB= $pk_schema ne "%"C= $pk_schema ne $table_info{$row->{"table"}}{"schema"}
ABCresult
0XX0
10X0
1100
1111
631  
632 # cribbed from DBIx::Class::Schema::Loader::DBI::SQLite
633 my $rel = $rels[ $row->{id} ] ||= {
634 local_columns => [],
635 remote_columns => undef,
636 remote_table => $row->{table},
637 13 ▶ };
Condition100%2/2
$rels[$row->{"id"}] ||= {"local_columns", [], "remote_columns", undef, "remote_table", $row->{"table"}}
l!l
211
MC/DC100%1/1
$rels[$row->{"id"}] ||= {"local_columns", [], "remote_columns", undef, "remote_table", $row->{"table"}}
$rels[$row->{"id"}]
Truth table100%2/2
A
A= $rels[$row->{"id"}]
Aresult
11
00
638 13 push @{ $rel->{local_columns} }, $row->{from};
639 13 push @{ $rel->{remote_columns} }, $row->{to}
640 13 ▶ if defined $row->{to};
Branch: 1 branch
BranchTrueFalseTotal
if defined $row->{"to"} 13 0 13
641  
642 my $fk_row = {
643 PKTABLE_CAT => undef,
644 PKTABLE_SCHEM => $table_info{$row->{table}}{schema},
645 PKTABLE_NAME => $row->{table},
646 PKCOLUMN_NAME => $row->{to},
647 FKTABLE_CAT => undef,
648 FKTABLE_SCHEM => $dbname,
649 FKTABLE_NAME => $tbname,
650 FKCOLUMN_NAME => $row->{from},
651 KEY_SEQ => $row->{seq} + 1,
652 UPDATE_RULE => $DBI_code_for_rule{$row->{on_update}},
653 DELETE_RULE => $DBI_code_for_rule{$row->{on_delete}},
654 FK_NAME => undef,
655 PK_NAME => undef,
656 DEFERRABILITY => undef,
657 13 ▶ UNIQUE_OR_PRIMARY => $table_info{$row->{table}}{columns}{$row->{to}} ? 'PRIMARY' : 'UNIQUE',
Branch: 1 branch
BranchTrueFalseTotal
$table_info{$row->{'table'}}{'columns'}{$row->{'to'}} ? : 10 3 13
658 };
659 13 push @fk_info, $fk_row;
660 13 push @{ $relid2rels{$row->{id}} }, $fk_row; # keep so can fixup
661 }
662  
663 # cribbed from DBIx::Class::Schema::Loader::DBI::SQLite
664 # but with additional parsing of which kind of deferrable
665 14 REL: for my $relid (keys %relid2rels) {
666 11 my $rel = $rels[$relid];
667 11 my $deferrable = $DBI_code_for_rule{'NOT DEFERRABLE'};
668 11 my $local_cols = '"?' . (join '"? \s* , \s* "?', map quotemeta, @{ $rel->{local_columns} }) . '"?';
669 11 ▶ my $remote_cols = '"?' . (join '"? \s* , \s* "?', map quotemeta, @{ $rel->{remote_columns} || [] }) . '"?';
Condition50%1/2
$rel->{'remote_columns'} || []
l!l
110
MC/DC0%0/1
$rel->{'remote_columns'} || []
$rel->{'remote_columns'}
Truth table50%1/2
A
A= $rel->{'remote_columns'}
Aresult
11
00
670 11 my ($deferrable_clause) = $ddl =~ /
671 foreign \s+ key \s* \( \s* $local_cols \s* \) \s* references \s* (?:\S+|".+?(?<!")") \s*
672 (?:\( \s* $remote_cols \s* \) \s*)?
673 $DEFERRABLE_RE
674 /sxi;
675 11 ▶ if (!$deferrable_clause) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($deferrable_clause) 11 0 11
676 # check for inline constraint if 1 local column
677 11 ▶ if (@{ $rel->{local_columns} } == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rel->{"local_columns"};} == 1) 9 2 11
678 9 my ($local_col) = @{ $rel->{local_columns} };
679 9 ▶ my ($remote_col) = @{ $rel->{remote_columns} || [] };
Condition50%1/2
$rel->{'remote_columns'} || []
l!l
90
MC/DC0%0/1
$rel->{'remote_columns'} || []
$rel->{'remote_columns'}
Truth table50%1/2
A
A= $rel->{'remote_columns'}
Aresult
11
00
680 9 ▶ $remote_col ||= '';
Condition50%1/2
$remote_col ||= ""
l!l
90
MC/DC0%0/1
$remote_col ||= ""
$remote_col
Truth table50%1/2
A
A= $remote_col
Aresult
11
00
681 9 ($deferrable_clause) = $ddl =~ /
682 "?\Q$local_col\E"? \s* (?:\w+\s*)* (?: \( \s* \d\+ (?:\s*,\s*\d+)* \s* \) )? \s*
683 references \s+ (?:\S+|".+?(?<!")") (?:\s* \( \s* "?\Q$remote_col\E"? \s* \))? \s*
684 $DEFERRABLE_RE
685 /sxi;
686 }
687 }
688 11 ▶ if ($deferrable_clause) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deferrable_clause) 3 8 11
689 # default is already NOT
690 3 ▶ if ($deferrable_clause !~ /not/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($deferrable_clause =~ /not/i) 3 0 3
691 $deferrable = $deferrable_clause =~ /deferred/i
692 ? $DBI_code_for_rule{'INITIALLY DEFERRED'}
693 3 ▶ : $DBI_code_for_rule{'INITIALLY IMMEDIATE'};
Branch: 1 branch
BranchTrueFalseTotal
$deferrable_clause =~ /deferred/i ? : 0 3 3
694 }
695 }
696 11 $_->{DEFERRABILITY} = $deferrable for @{ $relid2rels{$relid} };
697 }
698 }
699 }
700  
701 10 ▶ my $sponge_dbh = DBI->connect("DBI:Sponge:", "", "")
Branch: 1 branch
BranchTrueFalseTotal
my $sponge_dbh = "DBI"->connect("DBI:Sponge:", "", "") or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr") 10 0 10
702 or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr");
703 my $sponge_sth = $sponge_dbh->prepare("foreign_key_info", {
704 NAME => \@FOREIGN_KEY_INFO_ODBC,
705 10 ▶ rows => [ map { [@{$_}{@FOREIGN_KEY_INFO_ODBC} ] } @fk_info ],
Branch: 1 branch
BranchTrueFalseTotal
my $sponge_sth = $sponge_dbh->prepare("foreign_key_info", {"NAME", \@FOREIGN_KEY_INFO_ODBC, "rows", [map({[@{$_;}{@FOREIGN_KEY_INFO_ODBC}];} @fk_info)], "NUM_OF_FIELDS", scalar @FOREIGN_KEY_INFO_ODBC}) or return $dbh->DBI::set_err($sponge_dbh->err, $sponge_dbh->errstr) 10 0 10
706 NUM_OF_FIELDS => scalar(@FOREIGN_KEY_INFO_ODBC),
707 }) or return $dbh->DBI::set_err(
708 $sponge_dbh->err,
709 $sponge_dbh->errstr,
710 );
711 10 return $sponge_sth;
712 }
713  
714 116 my @STATISTICS_INFO_ODBC = (
715 'TABLE_CAT', # The catalog identifier.
716 'TABLE_SCHEM', # The schema identifier.
717 'TABLE_NAME', # The table identifier.
718 'NON_UNIQUE', # Unique index indicator.
719 'INDEX_QUALIFIER', # Index qualifier identifier.
720 'INDEX_NAME', # The index identifier.
721 'TYPE', # The type of information being returned.
722 'ORDINAL_POSITION', # Column sequence number (starting with 1).
723 'COLUMN_NAME', # The column identifier.
724 'ASC_OR_DESC', # Column sort sequence.
725 'CARDINALITY', # Cardinality of the table or index.
726 'PAGES', # Number of storage pages used by this table or index.
727 'FILTER_CONDITION', # The index filter condition as a string.
728 );
729  
730 4 ▶sub statistics_info {
Subroutine statistics_info: called CC=25 SCAR=34.6
731 4 my ($dbh, $catalog, $schema, $table, $unique_only, $quick) = @_;
732  
733 4 ▶ my $databases = $dbh->selectall_arrayref("PRAGMA database_list", {Slice => {}}) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $databases = $dbh->selectall_arrayref("PRAGMA database_list", {"Slice", {}}) or return 4 0 4
734  
735 4 my @statistics_info;
736 4 for my $database (@$databases) {
737 8 my $dbname = $database->{name};
738 8 ▶ next if defined $schema && $schema ne '%' && $schema ne $dbname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $schema and $schema ne "%" and $schema ne $dbname 0 8 8
Condition33%2/6
defined $schema and $schema ne "%" and $schema ne $dbname
!ll&&!rl&&r
800
defined $schema and $schema ne "%"
!ll&&!rl&&r
800
MC/DC0%0/3
defined $schema and $schema ne "%" and $schema ne $dbname
defined $schema $schema ne "%" $schema ne $dbname
Truth table25%1/4
A and B and C
A= defined $schemaB= $schema ne "%"C= $schema ne $dbname
ABCresult
0XX0
10X0
1100
1111
739  
740 8 my $quoted_dbname = $dbh->quote_identifier($dbname);
741 8 ▶ my $master_table =
Branch: 2 branches
BranchTrueFalseTotal
$dbname eq 'main' ? : 4 4 8
$dbname eq 'temp' ? : 0 4 4
742 ($dbname eq 'main') ? 'sqlite_master' :
743 ($dbname eq 'temp') ? 'sqlite_temp_master' :
744 $quoted_dbname.'.sqlite_master';
745  
746 8 ▶ my $tables = $dbh->selectall_arrayref("SELECT name FROM $master_table WHERE type = ?", undef, "table") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tables = $dbh->selectall_arrayref("SELECT name FROM $master_table WHERE type = ?", undef, "table") or return 8 0 8
747 8 for my $table_ref (@$tables) {
748 8 my $tbname = $table_ref->[0];
749 8 ▶ next if defined $table && $table ne '%' && uc($table) ne uc($tbname);
Branch: 1 branch
BranchTrueFalseTotal
if defined $table and $table ne "%" and uc $table ne uc $tbname 4 4 8
Condition50%3/6
defined $table and $table ne "%" and uc $table ne uc $tbname
!ll&&!rl&&r
044
defined $table and $table ne "%"
!ll&&!rl&&r
008
MC/DC33%1/3
defined $table and $table ne "%" and uc $table ne uc $tbname
defined $table $table ne "%" uc $table ne uc $tbname
Truth table50%2/4
A and B and C
A= defined $tableB= $table ne "%"C= uc $table ne uc $tbname
ABCresult
0XX0
10X0
1100
1111
750  
751 4 my $quoted_tbname = $dbh->quote_identifier($tbname);
752 4 ▶ my $sth = $dbh->prepare("PRAGMA $quoted_dbname.index_list($quoted_tbname)") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare("PRAGMA $quoted_dbname.index_list($quoted_tbname)") or return 4 0 4
753 4 ▶ $sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return 4 0 4
754 4 ▶ while(my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 16 4 20
755  
756 16 ▶ next if $unique_only && !$row->{unique};
Branch: 1 branch
BranchTrueFalseTotal
if $unique_only and not $row->{"unique"} 4 12 16
Condition100%3/3
$unique_only and not $row->{"unique"}
!ll&&!rl&&r
844
MC/DC100%2/2
$unique_only and not $row->{"unique"}
$unique_only not $row->{"unique"}
Truth table100%3/3
A and not(B)
A= $unique_onlyB= not $row->{"unique"}
ABresult
0X0
100
111
757 12 my $quoted_idx = $dbh->quote_identifier($row->{name});
758 12 for my $db (@$databases) {
759 24 my $quoted_db = $dbh->quote_identifier($db->{name});
760 24 ▶ my $i_sth = $dbh->prepare("PRAGMA $quoted_db.index_info($quoted_idx)") or return;
Branch: 1 branch
BranchTrueFalseTotal
my $i_sth = $dbh->prepare("PRAGMA $quoted_db.index_info($quoted_idx)") or return 24 0 24
761 24 ▶ $i_sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$i_sth->execute or return 24 0 24
762 24 my $cols = {};
763 24 ▶ while(my $info = $i_sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = $i_sth->fetchrow_hashref) 16 24 40
764 push @statistics_info, {
765 TABLE_CAT => undef,
766 TABLE_SCHEM => $db->{name},
767 TABLE_NAME => $tbname,
768 NON_UNIQUE => $row->{unique} ? 0 : 1,
769 INDEX_QUALIFIER => undef,
770 INDEX_NAME => $row->{name},
771 TYPE => 'btree', # see https://www.sqlite.org/version3.html esp. "Traditional B-trees are still used for indices"
772 ORDINAL_POSITION => $info->{seqno} + 1,
773 COLUMN_NAME => $info->{name},
774 16 ▶ ASC_OR_DESC => undef,
Branch: 1 branch
BranchTrueFalseTotal
$row->{'unique'} ? : 12 4 16
775 CARDINALITY => undef,
776 PAGES => undef,
777 FILTER_CONDITION => undef,
778 };
779 }
780 }
781 }
782 }
783 }
784  
785 4 ▶ my $sponge_dbh = DBI->connect("DBI:Sponge:", "", "")
Branch: 1 branch
BranchTrueFalseTotal
my $sponge_dbh = "DBI"->connect("DBI:Sponge:", "", "") or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr") 4 0 4
786 or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr");
787 my $sponge_sth = $sponge_dbh->prepare("statistics_info", {
788 NAME => \@STATISTICS_INFO_ODBC,
789 4 ▶ rows => [ map { [@{$_}{@STATISTICS_INFO_ODBC} ] } @statistics_info ],
Branch: 1 branch
BranchTrueFalseTotal
my $sponge_sth = $sponge_dbh->prepare("statistics_info", {"NAME", \@STATISTICS_INFO_ODBC, "rows", [map({[@{$_;}{@STATISTICS_INFO_ODBC}];} @statistics_info)], "NUM_OF_FIELDS", scalar @STATISTICS_INFO_ODBC}) or return $dbh->DBI::set_err($sponge_dbh->err, $sponge_dbh->errstr) 4 0 4
790 NUM_OF_FIELDS => scalar(@STATISTICS_INFO_ODBC),
791 }) or return $dbh->DBI::set_err(
792 $sponge_dbh->err,
793 $sponge_dbh->errstr,
794 );
795 4 return $sponge_sth;
796 }
797  
798 116 my @TypeInfoKeys = qw/
799 TYPE_NAME
800 DATA_TYPE
801 COLUMN_SIZE
802 LITERAL_PREFIX
803 LITERAL_SUFFIX
804 CREATE_PARAMS
805 NULLABLE
806 CASE_SENSITIVE
807 SEARCHABLE
808 UNSIGNED_ATTRIBUTE
809 FIXED_PREC_SCALE
810 AUTO_UNIQUE_VALUE
811 LOCAL_TYPE_NAME
812 MINIMUM_SCALE
813 MAXIMUM_SCALE
814 SQL_DATA_TYPE
815 SQL_DATETIME_SUB
816 NUM_PREC_RADIX
817 INTERVAL_PRECISION
818 /;
819  
820 116 my %TypeInfo = (
821 SQL_INTEGER ,=> {
822 TYPE_NAME => 'INTEGER',
823 DATA_TYPE => SQL_INTEGER,
824 NULLABLE => 2, # no for integer primary key, otherwise yes
825 SEARCHABLE => 3,
826 },
827 SQL_DOUBLE ,=> {
828 TYPE_NAME => 'REAL',
829 DATA_TYPE => SQL_DOUBLE,
830 NULLABLE => 1,
831 SEARCHABLE => 3,
832 },
833 SQL_VARCHAR ,=> {
834 TYPE_NAME => 'TEXT',
835 DATA_TYPE => SQL_VARCHAR,
836 LITERAL_PREFIX => "'",
837 LITERAL_SUFFIX => "'",
838 NULLABLE => 1,
839 SEARCHABLE => 3,
840 },
841 SQL_BLOB ,=> {
842 TYPE_NAME => 'BLOB',
843 DATA_TYPE => SQL_BLOB,
844 NULLABLE => 1,
845 SEARCHABLE => 3,
846 },
847 SQL_UNKNOWN_TYPE ,=> {
848 DATA_TYPE => SQL_UNKNOWN_TYPE,
849 },
850 );
851  
852 0 ▶sub type_info_all {
Subroutine type_info_all: not called CC=2 SCAR=17.9
853 0 my $idx = 0;
854  
855 0 my @info = ({map {$_ => $idx++} @TypeInfoKeys});
856 0 for my $id (sort {$a <=> $b} keys %TypeInfo) {
857 0 push @info, [map {$TypeInfo{$id}{$_}} @TypeInfoKeys];
858 }
859 0 return \@info;
860 }
861  
862 116 my @COLUMN_INFO = qw(
863 TABLE_CAT
864 TABLE_SCHEM
865 TABLE_NAME
866 COLUMN_NAME
867 DATA_TYPE
868 TYPE_NAME
869 COLUMN_SIZE
870 BUFFER_LENGTH
871 DECIMAL_DIGITS
872 NUM_PREC_RADIX
873 NULLABLE
874 REMARKS
875 COLUMN_DEF
876 SQL_DATA_TYPE
877 SQL_DATETIME_SUB
878 CHAR_OCTET_LENGTH
879 ORDINAL_POSITION
880 IS_NULLABLE
881 );
882  
883 7 ▶sub column_info {
Subroutine column_info: called CC=22 SCAR=31.8
884 7 my ($dbh, $cat_val, $sch_val, $tbl_val, $col_val) = @_;
885  
886 7 ▶ if ( defined $col_val and $col_val eq '%' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $col_val and $col_val eq "%") 1 6 7
Condition100%3/3
defined $col_val and $col_val eq "%"
!ll&&!rl&&r
151
MC/DC100%2/2
defined $col_val and $col_val eq "%"
defined $col_val $col_val eq "%"
Truth table100%3/3
A and B
A= defined $col_valB= $col_val eq "%"
ABresult
0X0
100
111
887 1 $col_val = undef;
888 }
889  
890 # Get a list of all tables ordered by TABLE_SCHEM, TABLE_NAME
891 7 my $sql = <<'END_SQL';
892 SELECT TABLE_SCHEM, tbl_name TABLE_NAME
893 FROM (
894 SELECT 'main' TABLE_SCHEM, tbl_name
895 FROM sqlite_master
896 WHERE type IN ('table','view')
897 UNION ALL
898 SELECT 'temp' TABLE_SCHEM, tbl_name
899 FROM sqlite_temp_master
900 WHERE type IN ('table','view')
901 END_SQL
902  
903 7 for my $db_name (_attached_database_list($dbh)) {
904 2 $sql .= <<"END_SQL";
905 UNION ALL
906 SELECT '$db_name' TABLE_SCHEM, tbl_name
907 FROM "$db_name".sqlite_master
908 WHERE type IN ('table','view')
909 END_SQL
910 }
911  
912 7 $sql .= <<'END_SQL';
913 UNION ALL
914 SELECT 'main' TABLE_SCHEM, 'sqlite_master' tbl_name
915 UNION ALL
916 SELECT 'temp' TABLE_SCHEM, 'sqlite_temp_master' tbl_name
917 )
918 END_SQL
919  
920 7 my @where;
921 7 ▶ if ( defined $sch_val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sch_val) 0 7 7
922 0 push @where, "TABLE_SCHEM LIKE '$sch_val'";
923 }
924 7 ▶ if ( defined $tbl_val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tbl_val) 7 0 7
925 7 push @where, "TABLE_NAME LIKE '$tbl_val'";
926 }
927 7 ▶ $sql .= ' WHERE ' . join("\n AND ", @where ) . "\n" if @where;
Branch: 1 branch
BranchTrueFalseTotal
if @where 7 0 7
928 7 $sql .= " ORDER BY TABLE_SCHEM, TABLE_NAME\n";
929 7 ▶ my $sth_tables = $dbh->prepare($sql) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sth_tables = $dbh->prepare($sql) or return undef 7 0 7
930 7 ▶ $sth_tables->execute or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sth_tables->execute or return undef 7 0 7
931  
932 # Taken from Fey::Loader::SQLite
933 7 my @cols;
934 7 ▶ while ( my ($schema, $table) = $sth_tables->fetchrow_array ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth_tables->fetchrow_array) 9 7 16
935 9 ▶ my $sth_columns = $dbh->prepare(qq{PRAGMA "$schema".table_xinfo("$table")}) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth_columns = $dbh->prepare(qq[PRAGMA "$schema".table_xinfo("$table")]) or return 9 0 9
936 9 ▶ $sth_columns->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth_columns->execute or return 9 0 9
937  
938 9 ▶ for ( my $position = 1; my $col_info = $sth_columns->fetchrow_hashref; $position++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col_info = $sth_columns->fetchrow_hashref) 20 9 29
939 20 ▶ if ( defined $col_val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $col_val) 14 6 20
940 # This must do a LIKE comparison
941 14 ▶ my $sth = $dbh->prepare("SELECT '$col_info->{name}' LIKE '$col_val'") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare(qq[SELECT '$col_info->{"name"}' LIKE '${col_val}']) or return undef 14 0 14
942 14 ▶ $sth->execute or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return undef 14 0 14
943 # Skip columns that don't match $col_val
944 14 ▶ next unless ($sth->fetchrow_array)[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->fetchrow_array)[0] 7 7 14
945 }
946  
947 my %col = (
948 TABLE_SCHEM => $schema,
949 TABLE_NAME => $table,
950 COLUMN_NAME => $col_info->{name},
951 13 ORDINAL_POSITION => $position,
952 );
953  
954 13 my $type = $col_info->{type};
955 13 ▶ if ( $type =~ s/(\w+)\s*\(\s*(\d+)(?:\s*,\s*(\d+))?\s*\)/$1/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ s/(\w+)\s*\(\s*(\d+)(?:\s*,\s*(\d+))?\s*\)/$1/) 7 6 13
956 7 $col{COLUMN_SIZE} = $2;
957 7 $col{DECIMAL_DIGITS} = $3;
958 }
959  
960 13 $col{TYPE_NAME} = $type;
961  
962 13 ▶ if ( defined $col_info->{dflt_value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $col_info->{"dflt_value"}) 0 13 13
963 $col{COLUMN_DEF} = $col_info->{dflt_value}
964 0 }
965  
966 13 ▶ if ( $col_info->{notnull} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col_info->{'notnull'}) { } 2 11 13
967 2 $col{NULLABLE} = 0;
968 2 $col{IS_NULLABLE} = 'NO';
969 } else {
970 11 $col{NULLABLE} = 1;
971 11 $col{IS_NULLABLE} = 'YES';
972 }
973  
974 13 push @cols, \%col;
975 }
976 9 $sth_columns->finish;
977 }
978 7 $sth_tables->finish;
979  
980 7 ▶ my $sponge = DBI->connect("DBI:Sponge:", '','')
Branch: 1 branch
BranchTrueFalseTotal
my $sponge = "DBI"->connect("DBI:Sponge:", "", "") or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr") 7 0 7
981 or return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr");
982 $sponge->prepare( "column_info", {
983 7 ▶ rows => [ map { [ @{$_}{@COLUMN_INFO} ] } @cols ],
Branch: 1 branch
BranchTrueFalseTotal
$sponge->prepare("column_info", {"rows", [map({[@{$_;}{@COLUMN_INFO}];} @cols)], "NUM_OF_FIELDS", scalar @COLUMN_INFO, "NAME", [@COLUMN_INFO]}) or return $dbh->DBI::set_err($sponge->err, $sponge->errstr) 7 0 7
984 NUM_OF_FIELDS => scalar @COLUMN_INFO,
985 NAME => [ @COLUMN_INFO ],
986 } ) or return $dbh->DBI::set_err(
987 $sponge->err,
988 $sponge->errstr,
989 );
990 }
991  
992 #======================================================================
993 # An internal tied hash package used for %DBD::SQLite::COLLATION, to
994 # prevent people from unintentionally overriding globally registered collations.
995  
996 package # hide from PAUSE
997 DBD::SQLite::_WriteOnceHash;
998  
999 116 require Tie::Hash;
1000  
1001 116 our @ISA = qw(Tie::StdHash);
1002  
1003 116 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
1004 116 bless {}, $_[0];
1005 }
1006  
1007 237 ▶sub STORE {
Subroutine STORE: called CC=2 SCAR=6.9
1008 237 ▶ ! exists $_[0]->{$_[1]} or die "entry $_[1] already registered";
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{$_[1]} and die "entry $_[1] already registered" 2 235 237
1009 235 $_[0]->{$_[1]} = $_[2];
1010 }
1011  
1012 1 ▶sub DELETE {
Subroutine DELETE: called CC=1 SCAR=0.0
1013 1 die "deletion of entry $_[1] is forbidden";
1014 }
1015  
1016 116 1;
1017  
1018 __END__
↑ Summary blib/lib/DBD/SQLite/VirtualTable/FileContent.pm »