Fixed deadlock test
[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
4ce3b851 6use base qw/DBIx::Class::Storage::DBI::MultiColumnIn/;
843f8ecd 7
87aa29e2 8__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL');
843f8ecd 9
e96a93df 10sub with_deferred_fk_checks {
11 my ($self, $sub) = @_;
12
13 $self->dbh->do('SET foreign_key_checks=0');
14 $sub->();
15 $self->dbh->do('SET foreign_key_checks=1');
16}
17
f86589ef 18sub connect_call_set_ansi_mode {
19 my $self = shift;
20 $self->dbh->do(q|SET sql_mode = 'ANSI,TRADITIONAL'|);
21 $self->dbh->do(q|SET sql_mode = 'ANSI,TRADITIONAL'|);
22}
23
d4f16b21 24sub _dbh_last_insert_id {
25 my ($self, $dbh, $source, $col) = @_;
26 $dbh->{mysql_insertid};
843f8ecd 27}
28
e8d293df 29sub sqlt_type {
30 return 'MySQL';
31}
32
adb3554a 33sub _svp_begin {
eeb8cfeb 34 my ($self, $name) = @_;
adb3554a 35
eeb8cfeb 36 $self->dbh->do("SAVEPOINT $name");
adb3554a 37}
38
39sub _svp_release {
eeb8cfeb 40 my ($self, $name) = @_;
adb3554a 41
eeb8cfeb 42 $self->dbh->do("RELEASE SAVEPOINT $name");
adb3554a 43}
44
45sub _svp_rollback {
eeb8cfeb 46 my ($self, $name) = @_;
adb3554a 47
eeb8cfeb 48 $self->dbh->do("ROLLBACK TO SAVEPOINT $name")
adb3554a 49}
f797e89e 50
106d5f3b 51sub is_replicating {
f797e89e 52 my $status = shift->dbh->selectrow_hashref('show slave status');
53 return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
106d5f3b 54}
55
56sub lag_behind_master {
f797e89e 57 return shift->dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
106d5f3b 58}
59
613f65e5 60# MySql can not do subquery update/deletes, only way is slow per-row operations.
ab807c12 61# This assumes you have set proper transaction isolation and use innodb.
b5963465 62sub _subq_update_delete {
613f65e5 63 return shift->_per_row_update_delete (@_);
64}
65
b5963465 66# MySql chokes on things like:
67# COUNT(*) FROM (SELECT tab1.col, tab2.col FROM tab1 JOIN tab2 ... )
68# claiming that col is a duplicate column (it loses the table specifiers by
69# the time it gets to the *). Thus for any subquery count we select only the
70# primary keys of the main table in the inner query. This hopefully still
71# hits the indexes and keeps mysql happy.
72# (mysql does not care if the SELECT and the GROUP BY match)
5960a195 73sub _subq_count_select {
74 my ($self, $source, $rs_attrs) = @_;
75 my @pcols = map { join '.', $rs_attrs->{alias}, $_ } ($source->primary_columns);
76 return @pcols ? \@pcols : [ 1 ];
b5963465 77}
78
843f8ecd 791;
80
75d07914 81=head1 NAME
843f8ecd 82
83DBIx::Class::Storage::DBI::mysql - Automatic primary key class for MySQL
84
85=head1 SYNOPSIS
86
87 # In your table classes
88 __PACKAGE__->load_components(qw/PK::Auto Core/);
89 __PACKAGE__->set_primary_key('id');
90
91=head1 DESCRIPTION
92
93This class implements autoincrements for MySQL.
94
95=head1 AUTHORS
96
97Matt S. Trout <mst@shadowcatsystems.co.uk>
98
99=head1 LICENSE
100
101You may distribute this code under the same terms as Perl itself.
102
103=cut