blib/lib/DBD/SQLcipher.pm

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