DBIx/Class/Storage/DBI/mysql.pm

filter: Statementstmt 56.4% 35 / 62 Branchbran 55.5% 10 / 18 Conditioncond 17.6% 3 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 41.1% 7 / 17 Podpod 85.7% 6 / 7 totaltotal 46.2% 61 / 132 CC 16 SCAR 19.2
CC
16
Cov
49%
deployment_statements
20.0
_prep_for_execute
10.7
is_replicating
6.0
CRAP 6.8
« DBIx/Class/CDBICompat/GetSet.pm ↑ Summary DBIx/Class/CDBICompat/Copy.pm »
1 package DBIx::Class::Storage::DBI::mysql;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base qw/DBIx::Class::Storage::DBI/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::MySQL');
11 3 __PACKAGE__->sql_limit_dialect ('LimitXY');
12 3 __PACKAGE__->sql_quote_char ('`');
13  
14 3 __PACKAGE__->_use_multicolumn_in (1);
15  
16 sub with_deferred_fk_checks {
17 0 ▶ my ($self, $sub) = @_;
Subroutine with_deferred_fk_checks: not called CC=1 SCAR=6.9
Pod documented
18  
19 0 $self->_do_query('SET FOREIGN_KEY_CHECKS = 0');
20 0 $sub->();
21 0 $self->_do_query('SET FOREIGN_KEY_CHECKS = 1');
22 }
23  
24 sub connect_call_set_strict_mode {
25 0 ▶ my $self = shift;
Subroutine connect_call_set_strict_mode: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 # the @@sql_mode puts back what was previously set on the session handle
28 0 $self->_do_query(q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|);
29 0 $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|);
30 }
31  
32 sub _dbh_last_insert_id {
33 0 ▶ my ($self, $dbh, $source, $col) = @_;
Subroutine _dbh_last_insert_id: not called CC=1 SCAR=6.9
34 0 $dbh->{mysql_insertid};
35 }
36  
37 sub _prep_for_execute {
38 4 ▶ my $self = shift;
Subroutine _prep_for_execute: called CC=8 SCAR=23.7
39 #(my $op, $ident, $args) = @_;
40  
41 # Only update and delete need special double-subquery treatment
42 # Insert referencing the same table (i.e. SELECT MAX(id) + 1) seems
43 # to work just fine on MySQL
44 4 ▶ return $self->next::method(@_) if ( $_[0] eq 'select' or $_[0] eq 'insert' );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "select" or $_[0] eq "insert" 0 4 4
Condition33%1/3
$_[0] eq "select" or $_[0] eq "insert"
l!l&&r!l&&!r
004
MC/DC0%0/2
$_[0] eq "select" or $_[0] eq "insert"
$_[0] eq "select" $_[0] eq "insert"
Truth table33%1/3
A or B
A= $_[0] eq "select"B= $_[0] eq "insert"
ABresult
1X1
011
000
45  
46  
47 # FIXME FIXME FIXME - this is a terrible, gross, incomplete hack
48 # it should be trivial for mst to port this to DQ (and a good
49 # exercise as well, since we do not yet have such wide tree walking
50 # in place). For the time being this will work in limited cases,
51 # mainly complex update/delete, which is really all we want it for
52 # currently (allows us to fix some bugs without breaking MySQL in
53 # the process, and is also crucial for Shadow to be usable)
54  
55 # extract the source name, construct modification indicator re
56 4 my $sm = $self->sql_maker;
57  
58 4 my $target_name = $_[1]->from;
59  
60 4 ▶ if (ref $target_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $target_name) 2 2 4
61 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $target_name eq 'SCALAR' and $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x) { } 2 0 2
Condition33%1/3
ref $target_name eq "SCALAR" and $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
!ll&&!rl&&r
002
MC/DC0%0/2
ref $target_name eq "SCALAR" and $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
ref $target_name eq "SCALAR" $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
Truth table33%1/3
A and B
A= ref $target_name eq "SCALAR"B= $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
ABresult
0X0
100
111
62 ref $target_name eq 'SCALAR'
63 and
64 $$target_name =~ /^ (?:
65 \` ( [^`]+ ) \` #`
66 | ( [\w\-]+ )
67 ) $/x
68 ) {
69 # this is just a plain-ish name, which has been literal-ed for
70 # whatever reason
71 2 ▶ $target_name = (defined $1) ? $1 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 0 2 2
72 }
73 else {
74 # this is something very complex, perhaps a custom result source or whatnot
75 # can't deal with it
76 0 undef $target_name;
77 }
78 }
79  
80 local $sm->{_modification_target_referenced_re} =
81 4 ▶ qr/ (?<!DELETE) [\s\)] (?: FROM | JOIN ) \s (?: \` \Q$target_name\E \` | \Q$target_name\E ) [\s\(] /xi
Branch: 1 branch
BranchTrueFalseTotal
if $target_name 4 0 4
82 if $target_name;
83  
84 4 $self->next::method(@_);
85 }
86  
87 # here may seem like an odd place to override, but this is the first
88 # method called after we are connected *and* the driver is determined
89 # ($self is reblessed). See code flow in ::Storage::DBI::_populate_dbh
90 sub _run_connection_actions {
91 1 ▶ my $self = shift;
Subroutine _run_connection_actions: called CC=3 SCAR=13.3
92  
93 # default mysql_auto_reconnect to off unless explicitly set
94 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_dbh->{"mysql_auto_reconnect"} and not exists $self->_dbic_connect_attributes->{"mysql_auto_reconnect"}) 0 1 1
Condition33%1/3
$self->_dbh->{"mysql_auto_reconnect"} and not exists $self->_dbic_connect_attributes->{"mysql_auto_reconnect"}
!ll&&!rl&&r
100
MC/DC0%0/2
$self->_dbh->{"mysql_auto_reconnect"} and not exists $self->_dbic_connect_attributes->{"mysql_auto_reconnect"}
$self->_dbh->{"mysql_auto_reconnect"} not exists $self->_dbic_connect_attributes->{"mysql_auto_reconnect"}
Truth table33%1/3
A and not(B)
A= $self->_dbh->{"mysql_auto_reconnect"}B= not exists $self->_dbic_connect_attributes->{"mysql_auto_reconnect"}
ABresult
0X0
100
111
95 $self->_dbh->{mysql_auto_reconnect}
96 and
97 ! exists $self->_dbic_connect_attributes->{mysql_auto_reconnect}
98 ) {
99 0 $self->_dbh->{mysql_auto_reconnect} = 0;
100 }
101  
102 1 $self->next::method(@_);
103 }
104  
105 # we need to figure out what mysql version we're running
106 sub sql_maker {
107 27 ▶ my $self = shift;
Subroutine sql_maker: called CC=3 SCAR=11.0
Pod documented
108  
109 27 ▶ unless ($self->_sql_maker) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_sql_maker) 2 25 27
110 2 my $maker = $self->next::method (@_);
111  
112 # mysql 3 does not understand a bare JOIN
113 2 my $mysql_ver = $self->_dbh_get_info('SQL_DBMS_VER');
114 2 ▶ $maker->{_default_jointype} = 'INNER' if $mysql_ver =~ /^3/;
Branch: 1 branch
BranchTrueFalseTotal
if $mysql_ver =~ /^3/ 2 0 2
115 }
116  
117 27 return $self->_sql_maker;
118 }
119  
120 sub sqlt_type {
121 0 ▶ return 'MySQL';
Subroutine sqlt_type: not called CC=1 SCAR=6.9
Pod documented
122 }
123  
124 sub deployment_statements {
125 0 ▶ my $self = shift;
Subroutine deployment_statements: not called CC=4 SCAR=30.0
Pod documented
126 0 my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
127  
128 0 ▶ $sqltargs ||= {};
Condition0%0/2
$sqltargs ||= {}
l!l
00
MC/DC0%0/1
$sqltargs ||= {}
$sqltargs
Truth table0%0/2
A
A= $sqltargs
Aresult
11
00
129  
130 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $sqltargs->{"producer_args"}{"mysql_version"} and my $dver = $self->_server_info->{"normalized_dbms_version"}) 0 0 0
Condition0%0/3
not exists $sqltargs->{"producer_args"}{"mysql_version"} and my $dver = $self->_server_info->{"normalized_dbms_version"}
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $sqltargs->{"producer_args"}{"mysql_version"} and my $dver = $self->_server_info->{"normalized_dbms_version"}
not exists $sqltargs->{"producer_args"}{"mysql_version"} my $dver = $self->_server_info->{"normalized_dbms_version"}
Truth table0%0/3
not(A) and B
A= not exists $sqltargs->{"producer_args"}{"mysql_version"}B= my $dver = $self->_server_info->{"normalized_dbms_version"}
ABresult
0X0
100
111
131 ! exists $sqltargs->{producer_args}{mysql_version}
132 and
133 my $dver = $self->_server_info->{normalized_dbms_version}
134 ) {
135 0 $sqltargs->{producer_args}{mysql_version} = $dver;
136 }
137  
138 0 $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
139 }
140  
141 sub _exec_svp_begin {
142 0 ▶ my ($self, $name) = @_;
Subroutine _exec_svp_begin: not called CC=1 SCAR=6.9
143  
144 0 $self->_dbh->do("SAVEPOINT $name");
145 }
146  
147 sub _exec_svp_release {
148 0 ▶ my ($self, $name) = @_;
Subroutine _exec_svp_release: not called CC=1 SCAR=6.9
149  
150 0 $self->_dbh->do("RELEASE SAVEPOINT $name");
151 }
152  
153 sub _exec_svp_rollback {
154 0 ▶ my ($self, $name) = @_;
Subroutine _exec_svp_rollback: not called CC=1 SCAR=6.9
155  
156 0 $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
157 }
158  
159 sub is_replicating {
160 0 ▶ my $status = shift->_get_dbh->selectrow_hashref('show slave status');
Subroutine is_replicating: not called CC=2 SCAR=17.9
Pod documented
161 0 ▶ return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
Condition0%0/3
$status->{'Slave_IO_Running'} eq 'Yes' && $status->{'Slave_SQL_Running'} eq 'Yes'
!ll&&!rl&&r
000
MC/DC0%0/2
$status->{'Slave_IO_Running'} eq 'Yes' && $status->{'Slave_SQL_Running'} eq 'Yes'
$status->{'Slave_IO_Running'} eq 'Yes' $status->{'Slave_SQL_Running'} eq 'Yes'
Truth table0%0/3
A && B
A= $status->{'Slave_IO_Running'} eq 'Yes'B= $status->{'Slave_SQL_Running'} eq 'Yes'
ABresult
0X0
100
111
162 }
163  
164 sub lag_behind_master {
165 0 ▶ return shift->_get_dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
Subroutine lag_behind_master: not called CC=1 SCAR=6.9
Pod documented
166 }
167  
168 3 1;
169  
170 =head1 NAME
171  
172 DBIx::Class::Storage::DBI::mysql - Storage::DBI class implementing MySQL specifics
173  
174 =head1 SYNOPSIS
175  
176 Storage::DBI autodetects the underlying MySQL database, and re-blesses the
177 C<$storage> object into this class.
178  
179 my $schema = MyApp::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } );
180  
181 =head1 DESCRIPTION
182  
183 This class implements MySQL specific bits of L<DBIx::Class::Storage::DBI>,
184 like AutoIncrement column support and savepoints. Also it augments the
185 SQL maker to support the MySQL-specific C<STRAIGHT_JOIN> join type, which
186 you can use by specifying C<< join_type => 'straight' >> in the
187 L<relationship attributes|DBIx::Class::Relationship::Base/join_type>
188  
189  
190 It also provides a one-stop on-connect macro C<set_strict_mode> which sets
191 session variables such that MySQL behaves more predictably as far as the
192 SQL standard is concerned.
193  
194 =head1 STORAGE OPTIONS
195  
196 =head2 set_strict_mode
197  
198 Enables session-wide strict options upon connecting. Equivalent to:
199  
200 ->connect ( ... , {
201 on_connect_do => [
202 q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|,
203 q|SET SQL_AUTO_IS_NULL = 0|,
204 ]
205 });
206  
207 =head1 AUTHORS
208  
209 See L<DBIx::Class/CONTRIBUTORS>
210  
211 =head1 LICENSE
212  
213 You may distribute this code under the same terms as Perl itself.
214  
215 =cut
« DBIx/Class/CDBICompat/GetSet.pm ↑ Summary DBIx/Class/CDBICompat/Copy.pm »