DB/MySQL.pm

filter: Statementstmt 25.7% 61 / 237 Branchbran 0.8% 1 / 116 Conditioncond 2.2% 2 / 91 MC/DCmcdc 0.0% 0 / 53 Subroutinesub 23.0% 15 / 65 Podpod 50.0% 26 / 52 totaltotal 17.1% 105 / 614 CC 86 SCAR 39.8
CC
86
Cov
14%
parse_bitfield
262.0
refine_dbi_column_info
127.9
list_tables
56.0
CRAP 53.3
« DB/MariaDB.pm ↑ Summary DB/Oracle.pm »
1 package Rose::DB::MySQL;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 16 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 ▶use DateTime::Format::MySQL;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use SQL::ReservedWords::MySQL();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 TRY:
11 {
12 16 local $@;
13 16 eval { require DBD::mysql }; # Ignore errors
14 }
15  
16 16 ▶use Rose::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 16 our $VERSION = '0.774';
19  
20 16 our $Debug = 0;
21  
22 use Rose::Class::MakeMethods::Generic
23 16 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 16 inheritable_scalar =>
25 [
26 'supports_schema',
27 'coerce_autoincrement_to_serial',
28 ]
29 16 );
30  
31 16 __PACKAGE__->supports_schema(1);
32 16 __PACKAGE__->coerce_autoincrement_to_serial(1);
33  
34 #
35 # Object methods
36 #
37  
38 0 ▶sub registration_schema { shift->database }
Subroutine registration_schema: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 sub build_dsn
41 12 ▶{
Subroutine build_dsn: called CC=2 SCAR=7.1
Pod undocumented
42 12 my($self_or_class, %args) = @_;
43  
44 12 my %info;
45  
46 12 ▶ $info{'database'} = $args{'db'} || $args{'database'};
Condition33%1/3
$args{'db'} || $args{'database'}
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{'db'} || $args{'database'}
$args{'db'} $args{'database'}
Truth table33%1/3
A || B
A= $args{'db'}B= $args{'database'}
ABresult
1X1
011
000
47 12 $info{'host'} = $args{'host'};
48 12 $info{'port'} = $args{'port'};
49  
50 return
51 "dbi:mysql:" .
52 12 join(';', map { "$_=$info{$_}" } grep { defined $info{$_} }
53 qw(database host port));
54 }
55  
56 13 ▶sub dbi_driver { 'mysql' }
Subroutine dbi_driver: called CC=1 SCAR=0.0
Pod undocumented
57  
58 0 ▶sub mysql_auto_reconnect { shift->dbh_attribute_boolean('mysql_auto_reconnect', @_) }
Subroutine mysql_auto_reconnect: not called CC=1 SCAR=6.9
Pod documented
59 0 ▶sub mysql_client_found_rows { shift->dbh_attribute_boolean('mysql_client_found_rows', @_) }
Subroutine mysql_client_found_rows: not called CC=1 SCAR=6.9
Pod documented
60 0 ▶sub mysql_compression { shift->dbh_attribute_boolean('mysql_compression', @_) }
Subroutine mysql_compression: not called CC=1 SCAR=6.9
Pod documented
61 0 ▶sub mysql_connect_timeout { shift->dbh_attribute_boolean('mysql_connect_timeout', @_) }
Subroutine mysql_connect_timeout: not called CC=1 SCAR=6.9
Pod documented
62 0 ▶sub mysql_embedded_groups { shift->dbh_attribute('mysql_embedded_groups', @_) }
Subroutine mysql_embedded_groups: not called CC=1 SCAR=6.9
Pod documented
63 0 ▶sub mysql_embedded_options { shift->dbh_attribute('mysql_embedded_options', @_) }
Subroutine mysql_embedded_options: not called CC=1 SCAR=6.9
Pod documented
64 0 ▶sub mysql_local_infile { shift->dbh_attribute('mysql_local_infile', @_) }
Subroutine mysql_local_infile: not called CC=1 SCAR=6.9
Pod documented
65 0 ▶sub mysql_multi_statements { shift->dbh_attribute_boolean('mysql_multi_statements', @_) }
Subroutine mysql_multi_statements: not called CC=1 SCAR=6.9
Pod documented
66 0 ▶sub mysql_read_default_file { shift->dbh_attribute('mysql_read_default_file', @_) }
Subroutine mysql_read_default_file: not called CC=1 SCAR=6.9
Pod documented
67 0 ▶sub mysql_read_default_group { shift->dbh_attribute('mysql_read_default_group', @_) }
Subroutine mysql_read_default_group: not called CC=1 SCAR=6.9
Pod documented
68 0 ▶sub mysql_socket { shift->dbh_attribute('mysql_socket', @_) }
Subroutine mysql_socket: not called CC=1 SCAR=6.9
Pod documented
69 0 ▶sub mysql_ssl { shift->dbh_attribute_boolean('mysql_ssl', @_) }
Subroutine mysql_ssl: not called CC=1 SCAR=6.9
Pod documented
70 0 ▶sub mysql_ssl_ca_file { shift->dbh_attribute('mysql_ssl_ca_file', @_) }
Subroutine mysql_ssl_ca_file: not called CC=1 SCAR=6.9
Pod documented
71 0 ▶sub mysql_ssl_ca_path { shift->dbh_attribute('mysql_ssl_ca_path', @_) }
Subroutine mysql_ssl_ca_path: not called CC=1 SCAR=6.9
Pod documented
72 0 ▶sub mysql_ssl_cipher { shift->dbh_attribute('mysql_ssl_cipher', @_) }
Subroutine mysql_ssl_cipher: not called CC=1 SCAR=6.9
Pod documented
73 0 ▶sub mysql_ssl_client_cert { shift->dbh_attribute('mysql_ssl_client_cert', @_) }
Subroutine mysql_ssl_client_cert: not called CC=1 SCAR=6.9
Pod documented
74 0 ▶sub mysql_ssl_client_key { shift->dbh_attribute('mysql_ssl_client_key', @_) }
Subroutine mysql_ssl_client_key: not called CC=1 SCAR=6.9
Pod documented
75 0 ▶sub mysql_use_result { shift->dbh_attribute_boolean('mysql_use_result', @_) }
Subroutine mysql_use_result: not called CC=1 SCAR=6.9
Pod documented
76 0 ▶sub mysql_bind_type_guessing { shift->dbh_attribute_boolean('mysql_bind_type_guessing', @_) }
Subroutine mysql_bind_type_guessing: not called CC=1 SCAR=6.9
Pod documented
77  
78 sub mysql_enable_utf8
79 0 ▶{
Subroutine mysql_enable_utf8: not called CC=3 SCAR=24.8
Pod documented
80 0 my($self) = shift;
81 0 ▶ $self->dbh->do('SET NAMES utf8') if(@_ && $self->has_dbh);
Branch: 1 branch
BranchTrueFalseTotal
if @_ and $self->has_dbh 0 0 0
Condition0%0/3
@_ and $self->has_dbh
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and $self->has_dbh
@_ $self->has_dbh
Truth table0%0/3
A and B
A= @_B= $self->has_dbh
ABresult
0X0
100
111
82 0 $self->dbh_attribute_boolean('mysql_enable_utf8', @_)
83 }
84  
85 sub mysql_enable_utf8mb4
86 0 ▶{
Subroutine mysql_enable_utf8mb4: not called CC=3 SCAR=24.8
Pod documented
87 0 my($self) = shift;
88 0 ▶ $self->dbh->do('SET NAMES utf8mb4') if(@_ && $self->has_dbh);
Branch: 1 branch
BranchTrueFalseTotal
if @_ and $self->has_dbh 0 0 0
Condition0%0/3
@_ and $self->has_dbh
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and $self->has_dbh
@_ $self->has_dbh
Truth table0%0/3
A and B
A= @_B= $self->has_dbh
ABresult
0X0
100
111
89 0 $self->dbh_attribute_boolean('mysql_enable_utf8mb4', @_)
90 }
91  
92 sub database_version
93 0 ▶{
Subroutine database_version: not called CC=4 SCAR=30.0
Pod undocumented
94 0 my($self) = shift;
95 0 ▶ return $self->{'database_version'} if(defined $self->{'database_version'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"database_version"} 0 0 0
96  
97 0 my $vers = $self->dbh->get_info(18); # SQL_DBMS_VER
98  
99 # Convert to an integer, e.g., 5.1.13 -> 5001013
100 0 ▶ if($vers =~ /^(\d+)\.(\d+)(?:\.(\d+))?/)
Branch: 1 branch
BranchTrueFalseTotal
if ($vers =~ /^(\d+)\.(\d+)(?:\.(\d+))?/) 0 0 0
101 {
102 0 ▶ $vers = sprintf('%d%03d%03d', $1, $2, $3 || 0);
Condition0%0/2
$3 || 0
l!l
00
MC/DC0%0/1
$3 || 0
$3
Truth table0%0/2
A
A= $3
Aresult
11
00
103 }
104  
105 0 return $self->{'database_version'} = $vers;
106 }
107  
108 sub init_dbh
109 12 ▶{
Subroutine init_dbh: called CC=1 SCAR=0.0
Pod undocumented
110 12 my($self) = shift;
111  
112 12 $self->{'supports_on_duplicate_key_update'} = undef;
113  
114 12 my $method = ref($self)->parent_class . '::init_dbh';
115  
116 16 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
117 12 return $self->$method(@_);
118 }
119  
120 0 ▶sub max_column_name_length { 64 }
Subroutine max_column_name_length: not called CC=1 SCAR=6.9
Pod undocumented
121 0 ▶sub max_column_alias_length { 255 }
Subroutine max_column_alias_length: not called CC=1 SCAR=6.9
Pod undocumented
122  
123 sub quote_column_name
124 0 ▶{
Subroutine quote_column_name: not called CC=1 SCAR=6.9
Pod undocumented
125 0 my $name = $_[1];
126 0 $name =~ s/`/``/g;
127 0 return qq(`$name`);
128 }
129  
130 sub quote_table_name
131 0 ▶{
Subroutine quote_table_name: not called CC=1 SCAR=6.9
Pod undocumented
132 0 my $name = $_[1];
133 0 $name =~ s/`/``/g;
134 0 return qq(`$name`);
135 }
136  
137 sub list_tables
138 0 ▶{
Subroutine list_tables: not called CC=7 SCAR=40.3
Pod undocumented
139 0 my($self, %args) = @_;
140  
141 0 ▶ my $types = $args{'include_views'} ? "'TABLE','VIEW'" : 'TABLE';
Branch: 1 branch
BranchTrueFalseTotal
$args{'include_views'} ? : 0 0 0
142 0 my @tables;
143  
144 0 my $schema = $self->schema;
145  
146 0 ▶ $schema = $self->database unless(defined $schema);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $schema 0 0 0
147  
148 0 my $error;
149  
150 TRY:
151 {
152 0 local $@;
153  
154 eval
155 0 {
156 0 ▶ my $dbh = $self->dbh or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or die $self->error 0 0 0
157  
158 0 local $dbh->{'RaiseError'} = 1;
159 0 local $dbh->{'FetchHashKeyName'} = 'NAME';
160  
161 0 my $sth = $dbh->table_info($self->catalog, $schema, '%', $types);
162  
163 0 $sth->execute;
164  
165 0 ▶ while(my $table_info = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $table_info = $sth->fetchrow_hashref) 0 0 0
166 {
167 0 push(@tables, $self->unquote_table_name($table_info->{'TABLE_NAME'}));
168 }
169 };
170  
171 0 $error = $@;
172 }
173  
174 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
175 {
176 0 Carp::croak "Could not list tables from ", $self->dsn, " - $error";
177 }
178  
179 0 ▶ return wantarray ? @tables : \@tables;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
180 }
181  
182 0 ▶sub init_date_handler { DateTime::Format::MySQL->new }
Subroutine init_date_handler: not called CC=1 SCAR=6.9
Pod undocumented
183  
184 0 ▶sub insertid_param { 'mysql_insertid' }
Subroutine insertid_param: not called CC=1 SCAR=6.9
Pod undocumented
185  
186 0 ▶sub last_insertid_from_sth { $_[1]->{'mysql_insertid'} }
Subroutine last_insertid_from_sth: not called CC=1 SCAR=6.9
Pod undocumented
187  
188 sub format_table_with_alias
189 0 ▶{
Subroutine format_table_with_alias: not called CC=7 SCAR=40.3
Pod undocumented
190 0 my($self, $table, $alias, $hints) = @_;
191  
192 0 my $version = $self->database_version;
193  
194 0 ▶ if($hints && $version >= 3_023_012)
Branch: 1 branch
BranchTrueFalseTotal
if ($hints and $version >= 3023012) 0 0 0
Condition0%0/3
$hints and $version >= 3023012
!ll&&!rl&&r
000
MC/DC0%0/2
$hints and $version >= 3023012
$hints $version >= 3023012
Truth table0%0/3
A and B
A= $hintsB= $version >= 3023012
ABresult
0X0
100
111
195 {
196 0 my $sql = "$table $alias ";
197  
198 # "ignore index()" and "use index()" were added in 3.23.12 (07 March 2000)
199 # "force index()" was added in 4.0.9 (09 January 2003)
200 0 ▶ my @types = (($version >= 4_000_009 ? 'force' : ()), qw(use ignore));
Branch: 1 branch
BranchTrueFalseTotal
$version >= 4000009 ? : 0 0 0
201  
202 0 foreach my $index_hint_type (@types)
203 {
204 0 my $key = "${index_hint_type}_index";
205  
206 0 ▶ if($hints->{$key})
Branch: 1 branch
BranchTrueFalseTotal
if ($hints->{$key}) 0 0 0
207 {
208 0 $sql .= uc($index_hint_type) . ' INDEX (';
209  
210 0 ▶ if(ref $hints->{$key} eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hints->{$key} eq 'ARRAY') { } 0 0 0
211 {
212 0 $sql .= join(', ', @{$hints->{$key}});
213 }
214 0 else { $sql .= $hints->{$key} }
215  
216 0 $sql .= ')';
217  
218 # Only one of these hints is allowed
219 0 last;
220 }
221 }
222  
223 0 return $sql;
224 }
225  
226 0 return "$table $alias";
227 }
228  
229 sub format_select_start_sql
230 0 ▶{
Subroutine format_select_start_sql: not called CC=5 SCAR=34.0
Pod undocumented
231 0 my($self, $hints) = @_;
232  
233 0 ▶ return 'SELECT' unless($hints);
Branch: 1 branch
BranchTrueFalseTotal
unless $hints 0 0 0
234  
235 return 'SELECT ' . ($hints->{'comment'} ? "/* $hints->{'comment'} */" : '') .
236 0 ▶ join(' ', (map { $hints->{$_} ? uc("sql_$_") : () }
Branch: 1 branch
BranchTrueFalseTotal
$hints->{$_} ? : 0 0 0
237 qw(small_result big_result buffer_result cache no_cache calc_found_rows)),
238 0 ▶ (map { $hints->{$_} ? uc($_) : () } qw(high_priority straight_join)));
Branch: 2 branches
BranchTrueFalseTotal
$hints->{'comment'} ? : 0 0 0
$hints->{$_} ? : 0 0 0
239 }
240  
241 sub format_select_lock
242 0 ▶{
Subroutine format_select_lock: not called CC=5 SCAR=34.0
Pod undocumented
243 0 my($self, $class, $lock, $tables_list) = @_;
244  
245 0 ▶ $lock = { type => $lock } unless(ref $lock);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $lock 0 0 0
246  
247 0 ▶ $lock->{'type'} ||= 'for update' if($lock->{'for_update'});
Branch: 1 branch
BranchTrueFalseTotal
if $lock->{"for_update"} 0 0 0
Condition0%0/2
$lock->{"type"} ||= "for update"
l!l
00
MC/DC0%0/1
$lock->{"type"} ||= "for update"
$lock->{"type"}
Truth table0%0/2
A
A= $lock->{"type"}
Aresult
11
00
248  
249 0 my %types =
250 (
251 'for update' => 'FOR UPDATE',
252 'shared' => 'LOCK IN SHARE MODE',
253 );
254  
255 0 ▶ my $sql = $types{$lock->{'type'}}
Branch: 1 branch
BranchTrueFalseTotal
my $sql = $types{$lock->{"type"}} or Carp::croak(qq[Invalid lock type: $lock->{"type"}]) 0 0 0
256 or Carp::croak "Invalid lock type: $lock->{'type'}";
257  
258 0 return $sql;
259 }
260  
261 sub validate_date_keyword
262 0 ▶{
Subroutine validate_date_keyword: not called CC=4 SCAR=25.0
Pod documented
263 16 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
264 0 ▶ !ref $_[1] && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)|
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] and $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/9
!ref($_[1]) && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/)
!ll&&!rl&&r
000
$_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xi or $_[0]->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$_[0]->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/4
!ref($_[1]) && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/)
!ref($_[1]) $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xi $_[0]->keyword_function_calls $_[1] =~ /^\w+\(.*\)$/
Truth table0%0/5
not(A) && B or C and D
A= !ref($_[1])B= $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xiC= $_[0]->keyword_function_callsD= $_[1] =~ /^\w+\(.*\)$/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
265 current_(?:time|date|timestamp)(?:\(\))?|0000-00-00)$/xi ||
266 ($_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/));
267 }
268  
269 sub validate_datetime_keyword
270 0 ▶{
Subroutine validate_datetime_keyword: not called CC=4 SCAR=25.0
Pod documented
271 16 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
272 0 ▶ !ref $_[1] && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)|
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] and $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/9
!ref($_[1]) && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/)
!ll&&!rl&&r
000
$_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xi or $_[0]->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$_[0]->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/4
!ref($_[1]) && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/)
!ref($_[1]) $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xi $_[0]->keyword_function_calls $_[1] =~ /^\w+\(.*\)$/
Truth table0%0/5
not(A) && B or C and D
A= !ref($_[1])B= $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xiC= $_[0]->keyword_function_callsD= $_[1] =~ /^\w+\(.*\)$/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
273 current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00)$/xi ||
274 ($_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/));
275 }
276  
277 sub validate_timestamp_keyword
278 0 ▶{
Subroutine validate_timestamp_keyword: not called CC=4 SCAR=25.0
Pod documented
279 16 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
280 0 ▶ !ref $_[1] && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)|
Branch: 1 branch
BranchTrueFalseTotal
not ref $_[1] and $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/ 0 0 0
Condition0%0/9
!ref($_[1]) && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/)
!ll&&!rl&&r
000
$_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xi or $_[0]->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
l!l&&r!l&&!r
000
$_[0]->keyword_function_calls and $_[1] =~ /^\w+\(.*\)$/
!ll&&!rl&&r
000
MC/DC0%0/4
!ref($_[1]) && ($_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xi || $_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/)
!ref($_[1]) $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xi $_[0]->keyword_function_calls $_[1] =~ /^\w+\(.*\)$/
Truth table0%0/5
not(A) && B or C and D
A= !ref($_[1])B= $_[1] =~ /^(?:(?:now|cur(?:date|time)|sysdate)\(\)| current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xiC= $_[0]->keyword_function_callsD= $_[1] =~ /^\w+\(.*\)$/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
281 current_(?:time|date|timestamp)(?:\(\))?|0000-00-00[ ]00:00:00|00000000000000)$/xi ||
282 ($_[0]->keyword_function_calls && $_[1] =~ /^\w+\(.*\)$/));
283 }
284  
285 16 *format_timestamp = \&Rose::DB::format_datetime;
286  
287 sub parse_bitfield
288 0 ▶{
Subroutine parse_bitfield: not called CC=17 SCAR=55.7
Pod undocumented
289 0 my($self, $val, $size, $from_db) = @_;
290  
291 0 ▶ if(ref $val)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) 0 0 0
292 {
293 0 ▶ if($size && $val->Size != $size)
Branch: 1 branch
BranchTrueFalseTotal
if ($size and $val->Size != $size) 0 0 0
Condition0%0/3
$size and $val->Size != $size
!ll&&!rl&&r
000
MC/DC0%0/2
$size and $val->Size != $size
$size $val->Size != $size
Truth table0%0/3
A and B
A= $sizeB= $val->Size != $size
ABresult
0X0
100
111
294 {
295 0 return Bit::Vector->new_Bin($size, $val->to_Bin);
296 }
297  
298 0 return $val;
299 }
300  
301 16 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
302 0 ▶ if($from_db && $val =~ /^\d+$/)
Branch: 5 branches
BranchTrueFalseTotal
if ($from_db and $val =~ /^\d+$/) { } 0 0 0
elsif ($val =~ /^[10]+$/) { } 0 0 0
elsif ($val =~ /^\d*[2-9]\d*$/) { } 0 0 0
elsif ($val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/ or $val =~ /^[0-9a-f]+$/i) { } 0 0 0
elsif ($val =~ s/^B'([10]+)'$/$1/i) { } 0 0 0
Condition0%0/3
$from_db and $val =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$from_db and $val =~ /^\d+$/
$from_db $val =~ /^\d+$/
Truth table0%0/3
A and B
A= $from_dbB= $val =~ /^\d+$/
ABresult
0X0
100
111
303 {
304 0 ▶ return Bit::Vector->new_Dec($size || (length($val) * 4), $val);
Condition0%0/3
$size || length($val) * 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length($val) * 4
$size length($val) * 4
Truth table0%0/3
A || B
A= $sizeB= length($val) * 4
ABresult
1X1
011
000
305 }
306 elsif($val =~ /^[10]+$/)
307 {
308 0 ▶ return Bit::Vector->new_Bin($size || length $val, $val);
Condition0%0/3
$size || length $val
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length $val
$size length $val
Truth table0%0/3
A || B
A= $sizeB= length $val
ABresult
1X1
011
000
309 }
310 elsif($val =~ /^\d*[2-9]\d*$/)
311 {
312 0 ▶ return Bit::Vector->new_Dec($size || (length($val) * 4), $val);
Condition0%0/3
$size || length($val) * 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length($val) * 4
$size length($val) * 4
Truth table0%0/3
A || B
A= $sizeB= length($val) * 4
ABresult
1X1
011
000
313 }
314 ▶ elsif($val =~ s/^0x// || $val =~ s/^X'(.*)'$/$1/ || $val =~ /^[0-9a-f]+$/i)
Condition0%0/6
$val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/ or $val =~ /^[0-9a-f]+$/i
l!l&&r!l&&!r
000
$val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/
l!l&&r!l&&!r
000
MC/DC0%0/3
$val =~ s/^0x// or $val =~ s/^X'(.*)'$/$1/ or $val =~ /^[0-9a-f]+$/i
$val =~ s/^0x// $val =~ s/^X'(.*)'$/$1/ $val =~ /^[0-9a-f]+$/i
Truth table0%0/4
A or B or C
A= $val =~ s/^0x//B= $val =~ s/^X'(.*)'$/$1/C= $val =~ /^[0-9a-f]+$/i
ABCresult
1XX1
01X1
0011
0000
315 {
316 0 ▶ return Bit::Vector->new_Hex($size || (length($val) * 4), $val);
Condition0%0/3
$size || length($val) * 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length($val) * 4
$size length($val) * 4
Truth table0%0/3
A || B
A= $sizeB= length($val) * 4
ABresult
1X1
011
000
317 }
318 elsif($val =~ s/^B'([10]+)'$/$1/i)
319 {
320 0 ▶ return Bit::Vector->new_Bin($size || length $val, $val);
Condition0%0/3
$size || length $val
l!l&&r!l&&!r
000
MC/DC0%0/2
$size || length $val
$size length $val
Truth table0%0/3
A || B
A= $sizeB= length $val
ABresult
1X1
011
000
321 }
322 else
323 {
324 0 return undef;
325 #return Bit::Vector->new_Bin($size || length($val), $val);
326 }
327 }
328  
329 sub format_bitfield
330 0 ▶{
Subroutine format_bitfield: not called CC=3 SCAR=24.8
Pod undocumented
331 0 my($self, $vec, $size) = @_;
332  
333 0 ▶ $vec = Bit::Vector->new_Bin($size, $vec->to_Bin) if($size);
Branch: 1 branch
BranchTrueFalseTotal
if $size 0 0 0
334  
335 # MySQL 5.0.3 or later requires this crap...
336 0 ▶ if($self->database_version >= 5_000_003)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->database_version >= 5000003) 0 0 0
337 {
338 0 return q(b') . $vec->to_Bin . q('); # 'CAST(' . $vec->to_Dec . ' AS UNSIGNED)';
339 }
340  
341 0 return hex($vec->to_Hex);
342 }
343  
344 0 ▶sub validate_bitfield_keyword { defined $_[1] ? 1 : 0 }
Subroutine validate_bitfield_keyword: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
345  
346 sub should_inline_bitfield_value
347 0 ▶{
Subroutine should_inline_bitfield_value: not called CC=3 SCAR=24.8
Pod undocumented
348 # MySQL 5.0.3 or later requires this crap...
349 0 ▶ return $_[0]->{'should_inline_bitfield_value'} ||=
Branch: 1 branch
BranchTrueFalseTotal
(shift())->database_version >= 5000003 ? : 0 0 0
Condition0%0/3
$_[0]{"should_inline_bitfield_value"} ||= (shift())->database_version >= 5000003 ? 1 : 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"should_inline_bitfield_value"} ||= (shift())->database_version >= 5000003 ? 1 : 0
$_[0]{"should_inline_bitfield_value"} (shift())->database_version >= 5000003 ? 1 : 0
Truth table0%0/3
A ||= B
A= $_[0]{"should_inline_bitfield_value"}B= (shift())->database_version >= 5000003 ? 1 : 0
ABresult
1X1
011
000
350 (shift->database_version >= 5_000_003) ? 1 : 0;
351 }
352  
353 sub select_bitfield_column_sql
354 0 ▶{
Subroutine select_bitfield_column_sql: not called CC=2 SCAR=17.9
Pod undocumented
355 0 my($self, $column, $table) = @_;
356  
357 # MySQL 5.0.3 or later requires this crap...
358 0 ▶ if($self->database_version >= 5_000_003)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->database_version >= 5000003) { } 0 0 0
359 {
360 0 return q{CONCAT("b'", BIN(} .
361 $self->auto_quote_column_with_table($column, $table) .
362 q{ + 0), "'")};
363 }
364 else
365 {
366 0 return $self->auto_quote_column_with_table($column, $table) . q{ + 0};
367 }
368 }
369  
370 sub parse_set
371 0 ▶{
Subroutine parse_set: not called CC=5 SCAR=34.0
Pod documented
372 0 my($self) = shift;
373  
374 0 ▶ return $_[0] if(ref $_[0] eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 0 0
375  
376 0 ▶ if(@_ > 1 && !ref $_[1])
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and not ref $_[1]) 0 0 0
Condition0%0/3
@_ > 1 and not ref $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 1 and not ref $_[1]
@_ > 1 not ref $_[1]
Truth table0%0/3
A and not(B)
A= @_ > 1B= not ref $_[1]
ABresult
0X0
100
111
377 {
378 0 pop(@_);
379 0 return [ @_ ];
380 }
381  
382 0 my $val = $_[0];
383  
384 0 ▶ return undef unless(defined $val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
385  
386 0 my @set = split(/,/, $val);
387  
388 0 return \@set;
389 }
390  
391 sub format_set
392 0 ▶{
Subroutine format_set: not called CC=5 SCAR=34.0
Pod documented
393 0 my($self) = shift;
394  
395 0 ▶ my @set = (ref $_[0]) ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
396  
397 0 ▶ return undef unless(@set && defined $set[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless @set and defined $set[0] 0 0 0
Condition0%0/3
@set and defined $set[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@set and defined $set[0]
@set defined $set[0]
Truth table0%0/3
A and B
A= @setB= defined $set[0]
ABresult
0X0
100
111
398  
399 return join(',', map
400 {
401 0 ▶ if(!defined $_)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_) { } 0 0 0
402 {
403 0 Carp::croak 'Undefined value found in array or list passed to ',
404 __PACKAGE__, '::format_set()';
405 }
406 0 else { $_ }
407 }
408 @set);
409 }
410  
411 sub refine_dbi_column_info
412 0 ▶{
Subroutine refine_dbi_column_info: not called CC=12 SCAR=48.5
Pod undocumented
413 0 my($self, $col_info) = @_;
414  
415 0 my $method = ref($self)->parent_class . '::refine_dbi_column_info';
416  
417 16 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
418 0 $self->$method($col_info);
419  
420 0 ▶ if($col_info->{'TYPE_NAME'} eq 'timestamp' && defined $col_info->{'COLUMN_DEF'})
Branch: 1 branch
BranchTrueFalseTotal
if ($col_info->{"TYPE_NAME"} eq "timestamp" and defined $col_info->{"COLUMN_DEF"}) 0 0 0
Condition0%0/3
$col_info->{"TYPE_NAME"} eq "timestamp" and defined $col_info->{"COLUMN_DEF"}
!ll&&!rl&&r
000
MC/DC0%0/2
$col_info->{"TYPE_NAME"} eq "timestamp" and defined $col_info->{"COLUMN_DEF"}
$col_info->{"TYPE_NAME"} eq "timestamp" defined $col_info->{"COLUMN_DEF"}
Truth table0%0/3
A and B
A= $col_info->{"TYPE_NAME"} eq "timestamp"B= defined $col_info->{"COLUMN_DEF"}
ABresult
0X0
100
111
421 {
422 0 ▶ if($col_info->{'COLUMN_DEF'} eq '0000-00-00 00:00:00' ||
Branch: 2 branches
BranchTrueFalseTotal
if ($col_info->{'COLUMN_DEF'} eq '0000-00-00 00:00:00' or $col_info->{'COLUMN_DEF'} eq '00000000000000') { } 0 0 0
elsif ($col_info->{'COLUMN_DEF'} eq 'CURRENT_TIMESTAMP') { } 0 0 0
Condition0%0/3
$col_info->{"COLUMN_DEF"} eq "0000-00-00 00:00:00" or $col_info->{"COLUMN_DEF"} eq "00000000000000"
l!l&&r!l&&!r
000
MC/DC0%0/2
$col_info->{"COLUMN_DEF"} eq "0000-00-00 00:00:00" or $col_info->{"COLUMN_DEF"} eq "00000000000000"
$col_info->{"COLUMN_DEF"} eq "0000-00-00 00:00:00" $col_info->{"COLUMN_DEF"} eq "00000000000000"
Truth table0%0/3
A or B
A= $col_info->{"COLUMN_DEF"} eq "0000-00-00 00:00:00"B= $col_info->{"COLUMN_DEF"} eq "00000000000000"
ABresult
1X1
011
000
423 $col_info->{'COLUMN_DEF'} eq '00000000000000')
424 {
425 # MySQL uses strange "all zeros" default values for timestamp fields.
426 # We'll just ignore them, since MySQL will use them internally no
427 # matter what we do. (But see the explicit_defaults_for_timestamp
428 # setting discussed below for some caveats.)
429 0 $col_info->{'COLUMN_DEF'} = undef;
430 }
431 elsif($col_info->{'COLUMN_DEF'} eq 'CURRENT_TIMESTAMP')
432 {
433 # Translate "current time" value into something that our date parser
434 # will understand.
435 #$col_info->{'COLUMN_DEF'} = 'now';
436  
437 # Actually, let the database handle this.
438 #
439 # Note: The new(ish) explicit_defaults_for_timestamp setting means we
440 # can't just set the default to undef and allow a NULL to be passed to
441 # MySQL which it will convert to a "current timestamp" value. We have to
442 # set a default explicitly to a value that will be passed as a literal to
443 # the server. See the relevant docs:
444 #
445 # https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp
446  
447 0 $col_info->{'COLUMN_DEF'} = 'NOW()';
448 }
449 }
450  
451 # Put valid SET and ENUM values in standard keys
452 0 ▶ if($col_info->{'TYPE_NAME'} eq 'set')
Branch: 2 branches
BranchTrueFalseTotal
if ($col_info->{'TYPE_NAME'} eq 'set') { } 0 0 0
elsif ($col_info->{'TYPE_NAME'} eq 'enum') { } 0 0 0
453 {
454  
455 0 $col_info->{'RDBO_SET_VALUES'} = $col_info->{'mysql_values'};
456 }
457 elsif($col_info->{'TYPE_NAME'} eq 'enum')
458 {
459 0 $col_info->{'RDBO_ENUM_VALUES'} = $col_info->{'mysql_values'};
460 }
461  
462 # Consider (big)int autoincrement to be (big)serial
463 0 ▶ if($col_info->{'mysql_is_auto_increment'} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($col_info->{"mysql_is_auto_increment"} and ref($self)->coerce_autoincrement_to_serial) 0 0 0
Condition0%0/3
$col_info->{"mysql_is_auto_increment"} and ref($self)->coerce_autoincrement_to_serial
!ll&&!rl&&r
000
MC/DC0%0/2
$col_info->{"mysql_is_auto_increment"} and ref($self)->coerce_autoincrement_to_serial
$col_info->{"mysql_is_auto_increment"} ref($self)->coerce_autoincrement_to_serial
Truth table0%0/3
A and B
A= $col_info->{"mysql_is_auto_increment"}B= ref($self)->coerce_autoincrement_to_serial
ABresult
0X0
100
111
464 ref($self)->coerce_autoincrement_to_serial)
465 {
466 0 ▶ if($col_info->{'TYPE_NAME'} eq 'int')
Branch: 2 branches
BranchTrueFalseTotal
if ($col_info->{'TYPE_NAME'} eq 'int') { } 0 0 0
elsif ($col_info->{'TYPE_NAME'} eq 'bigint') { } 0 0 0
467 {
468 0 $col_info->{'TYPE_NAME'} = 'serial';
469 }
470 elsif($col_info->{'TYPE_NAME'} eq 'bigint')
471 {
472 0 $col_info->{'TYPE_NAME'} = 'bigserial';
473 }
474 }
475  
476 0 return;
477 }
478  
479 0 ▶sub supports_arbitrary_defaults_on_insert { 1 }
Subroutine supports_arbitrary_defaults_on_insert: not called CC=1 SCAR=6.9
Pod undocumented
480 0 ▶sub likes_redundant_join_conditions { 1 }
Subroutine likes_redundant_join_conditions: not called CC=1 SCAR=6.9
Pod undocumented
481  
482 sub supports_on_duplicate_key_update
483 0 ▶{
Subroutine supports_on_duplicate_key_update: not called CC=3 SCAR=24.8
Pod undocumented
484 0 my($self) = shift;
485  
486 0 ▶ if(defined $self->{'supports_on_duplicate_key_update'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"supports_on_duplicate_key_update"}) 0 0 0
487 {
488 0 return $self->{'supports_on_duplicate_key_update'};
489 }
490  
491 0 ▶ if($self->database_version >= 4_001_000)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->database_version >= 4001000) 0 0 0
492 {
493 0 return $self->{'supports_on_duplicate_key_update'} = 1;
494 }
495  
496 0 return $self->{'supports_on_duplicate_key_update'} = 0;
497 }
498  
499 sub supports_select_from_subselect
500 0 ▶{
Subroutine supports_select_from_subselect: not called CC=3 SCAR=24.8
Pod undocumented
501 0 my($self) = shift;
502  
503 0 ▶ if(defined $self->{'supports_select_from_subselect'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"supports_select_from_subselect"}) 0 0 0
504 {
505 0 return $self->{'supports_select_from_subselect'};
506 }
507  
508 0 ▶ if($self->database_version >= 5_000_045)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->database_version >= 5000045) 0 0 0
509 {
510 0 return $self->{'supports_select_from_subselect'} = 1;
511 }
512  
513 0 return $self->{'supports_select_from_subselect'} = 0;
514 }
515  
516 #our %Reserved_Words = map { $_ => 1 } qw(read for case);
517 #sub is_reserved_word { $Reserved_Words{lc $_[1]} }
518  
519 16 *is_reserved_word = \&SQL::ReservedWords::MySQL::is_reserved;
520  
521 #
522 # Introspection
523 #
524  
525 sub _get_primary_key_column_names
526 0 ▶{
Subroutine _get_primary_key_column_names: not called CC=4 SCAR=30.0
527 0 my($self, $catalog, $schema, $table) = @_;
528  
529 0 ▶ my $dbh = $self->dbh or die $self->error;
Branch: 1 branch
BranchTrueFalseTotal
my $dbh = $self->dbh or die $self->error 0 0 0
530  
531 0 local $dbh->{'FetchHashKeyName'} = 'NAME';
532  
533 my $fq_table =
534 0 join('.', grep { defined } ($catalog, $schema,
535 $self->quote_table_name($table)));
536  
537 0 my $sth = $dbh->prepare("SHOW INDEX FROM $fq_table");
538 0 $sth->execute;
539  
540 0 my @columns;
541  
542 0 ▶ while(my $row = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
543 {
544 0 ▶ next unless($row->{'Key_name'} eq 'PRIMARY');
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"Key_name"} eq "PRIMARY" 0 0 0
545 0 push(@columns, $row->{'Column_name'});
546 }
547  
548 0 return \@columns;
549 }
550  
551 # Bury warning down here to make nice with version extractors
552 16 ▶if(defined $DBD::mysql::VERSION && $DBD::mysql::VERSION <= 2.9)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $DBD::mysql::VERSION and $DBD::mysql::VERSION <= "2.9") 0 16 16
Condition33%1/3
defined $DBD::mysql::VERSION and $DBD::mysql::VERSION <= "2.9"
!ll&&!rl&&r
1600
MC/DC0%0/2
defined $DBD::mysql::VERSION and $DBD::mysql::VERSION <= "2.9"
defined $DBD::mysql::VERSION $DBD::mysql::VERSION <= "2.9"
Truth table33%1/3
A and B
A= defined $DBD::mysql::VERSIONB= $DBD::mysql::VERSION <= "2.9"
ABresult
0X0
100
111
553 {
554 0 warn "WARNING: Rose::DB may not work correctly with DBD::mysql ",
555 "version 2.9 or earlier. You have version $DBD::mysql::VERSION";
556 }
557  
558 16 1;
559  
560 __END__
« DB/MariaDB.pm ↑ Summary DB/Oracle.pm »