blib/lib/DBD/SQLite.pm

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