Ask for newer DBD::Pg in author mode, suggest the newer version otherwise (proper...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / mysql.pm
CommitLineData
843f8ecd 1package DBIx::Class::Storage::DBI::mysql;
2
3use strict;
4use warnings;
5
698775ed 6use base qw/
7 DBIx::Class::Storage::DBI::MultiColumnIn
8 DBIx::Class::Storage::DBI::AmbiguousGlob
9 DBIx::Class::Storage::DBI
10/;
843f8ecd 11
87aa29e2 12__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL');
843f8ecd 13
e96a93df 14sub with_deferred_fk_checks {
15 my ($self, $sub) = @_;
16
17 $self->dbh->do('SET foreign_key_checks=0');
18 $sub->();
19 $self->dbh->do('SET foreign_key_checks=1');
20}
21
f86589ef 22sub connect_call_set_ansi_mode {
23 my $self = shift;
24 $self->dbh->do(q|SET sql_mode = 'ANSI,TRADITIONAL'|);
25 $self->dbh->do(q|SET sql_mode = 'ANSI,TRADITIONAL'|);
26}
27
d4f16b21 28sub _dbh_last_insert_id {
29 my ($self, $dbh, $source, $col) = @_;
30 $dbh->{mysql_insertid};
843f8ecd 31}
32
e8d293df 33sub sqlt_type {
34 return 'MySQL';
35}
36
adb3554a 37sub _svp_begin {
eeb8cfeb 38 my ($self, $name) = @_;
adb3554a 39
eeb8cfeb 40 $self->dbh->do("SAVEPOINT $name");
adb3554a 41}
42
43sub _svp_release {
eeb8cfeb 44 my ($self, $name) = @_;
adb3554a 45
eeb8cfeb 46 $self->dbh->do("RELEASE SAVEPOINT $name");
adb3554a 47}
48
49sub _svp_rollback {
eeb8cfeb 50 my ($self, $name) = @_;
adb3554a 51
eeb8cfeb 52 $self->dbh->do("ROLLBACK TO SAVEPOINT $name")
adb3554a 53}
48fe9087 54
106d5f3b 55sub is_replicating {
f797e89e 56 my $status = shift->dbh->selectrow_hashref('show slave status');
57 return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
106d5f3b 58}
59
60sub lag_behind_master {
f797e89e 61 return shift->dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
106d5f3b 62}
63
613f65e5 64# MySql can not do subquery update/deletes, only way is slow per-row operations.
ab807c12 65# This assumes you have set proper transaction isolation and use innodb.
b5963465 66sub _subq_update_delete {
613f65e5 67 return shift->_per_row_update_delete (@_);
68}
69
843f8ecd 701;
71
75d07914 72=head1 NAME
843f8ecd 73
74DBIx::Class::Storage::DBI::mysql - Automatic primary key class for MySQL
75
76=head1 SYNOPSIS
77
78 # In your table classes
79 __PACKAGE__->load_components(qw/PK::Auto Core/);
80 __PACKAGE__->set_primary_key('id');
81
82=head1 DESCRIPTION
83
84This class implements autoincrements for MySQL.
85
86=head1 AUTHORS
87
88Matt S. Trout <mst@shadowcatsystems.co.uk>
89
90=head1 LICENSE
91
92You may distribute this code under the same terms as Perl itself.
93
94=cut