blib/lib/DBIx/Class/Storage/DBI/MariaDB.pm

filter: Statementstmt 25.4% 15 / 59 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 18.7% 3 / 16 Podpod 85.7% 6 / 7 totaltotal 19.0% 24 / 126 CC 15 SCAR 32.0
CC
15
Cov
16%
_prep_for_execute
72.0
deployment_statements
20.0
_run_connection_actions
12.0
CRAP 24.5
↑ Summary
1 package DBIx::Class::Storage::DBI::MariaDB;
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 our $VERSION = '0.1.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(
29 q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|
30 );
31 0 $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|);
32 }
33  
34 sub _dbh_last_insert_id {
35 0 ▶ my ( $self, $dbh, $source, $col ) = @_;
Subroutine _dbh_last_insert_id: not called CC=1 SCAR=6.9
36 0 $dbh->{mariadb_insertid};
37 }
38  
39 sub _prep_for_execute {
40 0 ▶ my $self = shift;
Subroutine _prep_for_execute: not called CC=8 SCAR=42.8
41  
42 # Only update and delete need special double-subquery treatment
43 # Insert referencing the same table (i.e. SELECT MAX(id) + 1) seems
44 # to work just fine on MariaDB
45 0 ▶ return $self->next::method(@_)
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "select" or $_[0] eq "insert" 0 0 0
Condition0%0/3
$_[0] eq "select" or $_[0] eq "insert"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] eq "select" or $_[0] eq "insert"
$_[0] eq "select" $_[0] eq "insert"
Truth table0%0/3
A or B
A= $_[0] eq "select"B= $_[0] eq "insert"
ABresult
1X1
011
000
46 if ( $_[0] eq 'select' or $_[0] eq 'insert' );
47  
48 # FIXME FIXME FIXME - this is a terrible, gross, incomplete, MariaDB-specific
49 # hack but it works rather well for the limited amount of actual use cases
50 # which can not be done in any other way on MariaDB. This allows us to fix
51 # some bugs without breaking MariaDB support in the process and is also
52 # crucial for more complex things like Shadow to be usable
53 #
54 # This code is just a pre-analyzer, working in tandem with ::SQLMaker::MySQL,
55 # where the possibly-set value of {_modification_target_referenced_re} is
56 # used to demarcate which part of the final SQL to double-wrap in a subquery.
57 #
58 # This is covered extensively by "offline" tests, so that competing SQLMaker
59 # implementations could benefit from the existing tests just as well.
60  
61 # extract the source name, construct modification indicator re
62 0 my $sm = $self->sql_maker;
63  
64 0 my $target_name = $_[1]->from;
65  
66 0 ▶ if ( ref $target_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $target_name) 0 0 0
67 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $target_name eq 'SCALAR' and $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x) { } 0 0 0
Condition0%0/3
ref $target_name eq "SCALAR" and $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
!ll&&!rl&&r
000
MC/DC0%0/2
ref $target_name eq "SCALAR" and $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
ref $target_name eq "SCALAR" $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
Truth table0%0/3
A and B
A= ref $target_name eq "SCALAR"B= $$target_name =~ /^ (?: \` ( [^`]+ ) \` #` | ( [\w\-]+ ) ) $/x
ABresult
0X0
100
111
68 ref $target_name eq 'SCALAR'
69 and $$target_name =~ /^ (?:
70 \` ( [^`]+ ) \` #`
71 | ( [\w\-]+ )
72 ) $/x
73 )
74 {
75 # this is just a plain-ish name, which has been literal-ed for
76 # whatever reason
77 0 ▶ $target_name = ( defined $1 ) ? $1 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 0 0 0
78 } else {
79  
80 # this is something very complex, perhaps a custom result source or whatnot
81 # can't deal with it
82 0 undef $target_name;
83 }
84 }
85  
86 local $sm->{_modification_target_referenced_re} =
87 0 ▶qr/ (?<!DELETE) [\s\)] (?: FROM | JOIN ) \s (?: \` \Q$target_name\E \` | \Q$target_name\E ) [\s\(] /xi
Branch: 1 branch
BranchTrueFalseTotal
if $target_name 0 0 0
88 if $target_name;
89  
90 0 $self->next::method(@_);
91 }
92  
93 # here may seem like an odd place to override, but this is the first
94 # method called after we are connected *and* the driver is determined
95 # ($self is reblessed). See code flow in ::Storage::DBI::_populate_dbh
96 sub _run_connection_actions {
97 0 ▶ my $self = shift;
Subroutine _run_connection_actions: not called CC=3 SCAR=24.8
98  
99 # default mariadb_auto_reconnect to off unless explicitly set
100 0 ▶ if ( $self->_dbh->{mariadb_auto_reconnect}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_dbh->{"mariadb_auto_reconnect"} and not exists $self->_dbic_connect_attributes->{"mariadb_auto_reconnect"}) 0 0 0
Condition0%0/3
$self->_dbh->{"mariadb_auto_reconnect"} and not exists $self->_dbic_connect_attributes->{"mariadb_auto_reconnect"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_dbh->{"mariadb_auto_reconnect"} and not exists $self->_dbic_connect_attributes->{"mariadb_auto_reconnect"}
$self->_dbh->{"mariadb_auto_reconnect"} not exists $self->_dbic_connect_attributes->{"mariadb_auto_reconnect"}
Truth table0%0/3
A and not(B)
A= $self->_dbh->{"mariadb_auto_reconnect"}B= not exists $self->_dbic_connect_attributes->{"mariadb_auto_reconnect"}
ABresult
0X0
100
111
101 and !exists $self->_dbic_connect_attributes->{mariadb_auto_reconnect} )
102 {
103 0 $self->_dbh->{mariadb_auto_reconnect} = 0;
104 }
105  
106 0 $self->next::method(@_);
107 }
108  
109 # we need to figure out what mysql version we're running
110 sub sql_maker {
111 0 ▶ my $self = shift;
Subroutine sql_maker: not called CC=2 SCAR=17.9
Pod documented
112  
113 # it is critical to get the version *before* calling next::method
114 # otherwise the potential connect will obliterate the sql_maker
115 # next::method will populate in the _sql_maker accessor
116 0 my $mariadb_ver = $self->_server_info->{normalized_dbms_version};
117  
118 0 my $sm = $self->next::method(@_);
119  
120 # mysql 3 does not understand a bare JOIN
121 0 ▶ $sm->{_default_jointype} = 'INNER' if $mariadb_ver < 4;
Branch: 1 branch
BranchTrueFalseTotal
if $mariadb_ver < 4 0 0 0
122  
123 0 $sm;
124 }
125  
126 sub sqlt_type {
127 # used by SQL::Translator
128 0 ▶ return 'MySQL';
Subroutine sqlt_type: not called CC=1 SCAR=6.9
Pod documented
129 }
130  
131 sub deployment_statements {
132 0 ▶ my $self = shift;
Subroutine deployment_statements: not called CC=4 SCAR=30.0
Pod documented
133 0 my ( $schema, $type, $version, $dir, $sqltargs, @rest ) = @_;
134  
135 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
136  
137 0 ▶ if ( !exists $sqltargs->{producer_args}{mysql_version}
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
138 and my $dver = $self->_server_info->{normalized_dbms_version} )
139 {
140 0 $sqltargs->{producer_args}{mysql_version} = $dver;
141 }
142  
143 0 $self->next::method( $schema, $type, $version, $dir, $sqltargs, @rest );
144 }
145  
146 sub _exec_svp_begin {
147 0 ▶ my ( $self, $name ) = @_;
Subroutine _exec_svp_begin: not called CC=1 SCAR=6.9
148  
149 0 $self->_dbh->do("SAVEPOINT $name");
150 }
151  
152 sub _exec_svp_release {
153 0 ▶ my ( $self, $name ) = @_;
Subroutine _exec_svp_release: not called CC=1 SCAR=6.9
154  
155 0 $self->_dbh->do("RELEASE SAVEPOINT $name");
156 }
157  
158 sub _exec_svp_rollback {
159 0 ▶ my ( $self, $name ) = @_;
Subroutine _exec_svp_rollback: not called CC=1 SCAR=6.9
160  
161 0 $self->_dbh->do("ROLLBACK TO SAVEPOINT $name");
162 }
163  
164 sub is_replicating {
165 0 ▶ my $status = shift->_get_dbh->selectrow_hashref('show slave status');
Subroutine is_replicating: not called CC=2 SCAR=17.9
Pod documented
166 return ( $status->{Slave_IO_Running} eq 'Yes' )
167 0 ▶ && ( $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
168 }
169  
170 sub lag_behind_master {
171 return
172 shift->_get_dbh->selectrow_hashref('show slave status')
173 0 ▶ ->{Seconds_Behind_Master};
Subroutine lag_behind_master: not called CC=1 SCAR=6.9
Pod documented
174 }
175  
176 3 1;
177  
178 =head1 NAME
179  
180 DBIx::Class::Storage::DBI::MariaDB - Storage::DBI class implementing MariaDB specifics
181  
182 =head1 DESCRIPTION
183  
184 This module adds support for MariaDB in the DBIx::Class ORM. It supports
185 exactly the same parameters as the L<DBIx::Class::Storage::DBI::mysql>
186 module, so check that for further documentation.
187  
188 =head1 USAGE
189  
190 Similar to other storage modules that are builtin to DBIx::Class, all you need
191 to do is ensure DBIx::Class::Storage::DBI::MariaDB is loaded and specify
192 MariaDB in the DSN. For example:
193  
194 package MyApp::Schema;
195 use base 'DBIx::Class::Schema';
196  
197 # register classes
198 # ...
199 # load mariadb storage
200 __PACKAGE__->ensure_class_loaded('DBIx::Class::Storage::DBI::MariaDB');
201  
202 package MyApp;
203 use MyApp::Schema;
204  
205 my $dsn = "dbi:MariaDB:database=mydb";
206 my $user = "noone";
207 my $pass = "topsecret";
208 my $schema = MyApp::Schema->connect($dsn, $user, $pass);
209  
210 =head1 COPYRIGHT AND LICENSE
211  
212 Copyright (C) 2023 Siemplexus
213  
214 This library is free software; you can redistribute it and/or modify
215 it under the same terms as Perl itself.
216  
217 =head1 AUTHORS
218  
219 Antonis Kalou E<lt>a.kalou@shadowcat.co.ukE<gt>
220 Jess Robinson E<lt>j.robinson@shadowcat.co.ukE<gt>
↑ Summary