| 1 | package DBIO::MySQL::Storage::MariaDB; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MariaDB-specific storage for DBIO | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base qw/DBIO::MySQL::Storage/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | DBIO::Storage::DBI->register_driver('MariaDB' => __PACKAGE__); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | __PACKAGE__->sql_maker_class('DBIO::MySQL::SQLMaker::MariaDB'); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _dbh_last_insert_id { | ||||||||||||||||||||||||||
|
Subroutine
_dbh_last_insert_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 15 | 0 | my ($self, $dbh, $source, $col) = @_; | |||||||||||||||||||||||||||
| 16 | 0 | $dbh->{mariadb_insertid}; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub _run_connection_actions { | ||||||||||||||||||||||||||
|
Subroutine
_run_connection_actions: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_dbh->{"mariadb_auto_reconnect"} and not exists $self->_dbio_connect_attributes->{"mariadb_auto_reconnect"}
MC/DC0%0/2
$self->_dbh->{"mariadb_auto_reconnect"} and not exists $self->_dbio_connect_attributes->{"mariadb_auto_reconnect"}
$self->_dbh->{"mariadb_auto_reconnect"}
not exists $self->_dbio_connect_attributes->{"mariadb_auto_reconnect"}
Truth table0%0/3
A and not(B)
A= $self->_dbh->{"mariadb_auto_reconnect"}B= not exists $self->_dbio_connect_attributes->{"mariadb_auto_reconnect"}
| |||||||||||||||||||||||||||||
| 23 | $self->_dbh->{mariadb_auto_reconnect} | ||||||||||||||||||||||||||||
| 24 | and | ||||||||||||||||||||||||||||
| 25 | ! exists $self->_dbio_connect_attributes->{mariadb_auto_reconnect} | ||||||||||||||||||||||||||||
| 26 | ) { | ||||||||||||||||||||||||||||
| 27 | 0 | $self->_dbh->{mariadb_auto_reconnect} = 0; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | $self->DBIO::Storage::DBI::_run_connection_actions(@_); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _replication_status_row { | ||||||||||||||||||||||||||
|
Subroutine
_replication_status_row: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 35 | 0 | my $dbh = $self->_get_dbh; | |||||||||||||||||||||||||||
| 36 | # MariaDB 10.5+ renamed SHOW SLAVE STATUS to SHOW REPLICA STATUS; older | ||||||||||||||||||||||||||||
| 37 | # versions only know the legacy statement. Try modern first, fall back. | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return $dbh->selectrow_hashref('SHOW REPLICA STATUS') | ||||||||||||||||||||||||||
|
Condition0%0/3
$dbh->selectrow_hashref("SHOW REPLICA STATUS") // $dbh->selectrow_hashref("SHOW SLAVE STATUS")
MC/DC0%0/2
$dbh->selectrow_hashref("SHOW REPLICA STATUS") // $dbh->selectrow_hashref("SHOW SLAVE STATUS")
$dbh->selectrow_hashref("SHOW REPLICA STATUS")
$dbh->selectrow_hashref("SHOW SLAVE STATUS")
Truth table0%0/3
A // B
A= $dbh->selectrow_hashref("SHOW REPLICA STATUS")B= $dbh->selectrow_hashref("SHOW SLAVE STATUS")
| |||||||||||||||||||||||||||||
| 39 | // $dbh->selectrow_hashref('SHOW SLAVE STATUS'); | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub lag_behind_master { | ||||||||||||||||||||||||||
|
Subroutine
lag_behind_master: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $status = shift->_replication_status_row | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | or return undef; | ||||||||||||||||||||||||||||
| 46 | 0 | return $status->{Seconds_Behind_Master}; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =pod | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | DBIO::MySQL::Storage::MariaDB - MariaDB-specific storage for DBIO | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 VERSION | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | version 0.900001 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | package MyApp::Schema; | ||||||||||||||||||||||||||||
| 69 | use base 'DBIO::Schema'; | ||||||||||||||||||||||||||||
| 70 | __PACKAGE__->load_components('MySQL::MariaDB'); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my $schema = MyApp::Schema->connect($dsn, $user, $pass); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | MariaDB-specific storage backend for L<DBIO>. Extends L<DBIO::MySQL::Storage> | ||||||||||||||||||||||||||||
| 77 | with adaptations for L<DBD::MariaDB>: | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =over 4 | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item * | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Reads C<mariadb_insertid> instead of C<mysql_insertid> for last-insert-id | ||||||||||||||||||||||||||||
| 84 | retrieval. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =item * | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Disables C<mariadb_auto_reconnect> by default, consistent with the MySQL | ||||||||||||||||||||||||||||
| 89 | storage behavior, to prevent silent transaction loss. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item * | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Replication status queries use C<SHOW REPLICA STATUS> (MariaDB 10.5+) with | ||||||||||||||||||||||||||||
| 94 | fallback to C<SHOW SLAVE STATUS> for older servers. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =back | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | This class is auto-registered for the C<MariaDB> DBI driver and is activated | ||||||||||||||||||||||||||||
| 99 | when L<DBIO::MySQL::MariaDB/connection> is called. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 METHODS | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head2 is_replicating | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Returns true if the connected MariaDB replica is currently replicating (both | ||||||||||||||||||||||||||||
| 106 | IO and SQL threads running). Inherited from L<DBIO::MySQL::Storage>; | ||||||||||||||||||||||||||||
| 107 | C<_replication_status_row> is overridden to prefer C<SHOW REPLICA STATUS>. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head2 lag_behind_master | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Returns the number of seconds the replica is behind the master. Queries | ||||||||||||||||||||||||||||
| 112 | C<SHOW REPLICA STATUS> first, falling back to C<SHOW SLAVE STATUS> for older | ||||||||||||||||||||||||||||
| 113 | servers. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =seealso | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =over 4 | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =item * L<DBIO::MySQL::MariaDB> - Schema component that activates this storage | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item * L<DBIO::MySQL::Storage> - MySQL parent class | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =item * L<DBIO::MySQL> - Main distribution entry point | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =back | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||
| 134 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||
| 135 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 138 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||