blib/lib/DBD/SQLite.pm

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