Commit | Line | Data |
843f8ecd |
1 | package DBIx::Class::Storage::DBI::mysql; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
4ce3b851 |
6 | use base qw/DBIx::Class::Storage::DBI::MultiColumnIn/; |
843f8ecd |
7 | |
87aa29e2 |
8 | __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL'); |
843f8ecd |
9 | |
e96a93df |
10 | sub with_deferred_fk_checks { |
11 | my ($self, $sub) = @_; |
12 | |
5cf7285e |
13 | $self->_do_query('SET FOREIGN_KEY_CHECKS = 0'); |
e96a93df |
14 | $sub->(); |
5cf7285e |
15 | $self->_do_query('SET FOREIGN_KEY_CHECKS = 1'); |
e96a93df |
16 | } |
17 | |
f86589ef |
18 | sub connect_call_set_ansi_mode { |
19 | my $self = shift; |
5cf7285e |
20 | $self->_do_query(q|SET SQL_MODE = 'ANSI,TRADITIONAL'|); |
6a999241 |
21 | $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|); |
f86589ef |
22 | } |
23 | |
d4f16b21 |
24 | sub _dbh_last_insert_id { |
25 | my ($self, $dbh, $source, $col) = @_; |
26 | $dbh->{mysql_insertid}; |
843f8ecd |
27 | } |
28 | |
e8d293df |
29 | sub sqlt_type { |
30 | return 'MySQL'; |
31 | } |
32 | |
adb3554a |
33 | sub _svp_begin { |
eeb8cfeb |
34 | my ($self, $name) = @_; |
adb3554a |
35 | |
eeb8cfeb |
36 | $self->dbh->do("SAVEPOINT $name"); |
adb3554a |
37 | } |
38 | |
39 | sub _svp_release { |
eeb8cfeb |
40 | my ($self, $name) = @_; |
adb3554a |
41 | |
eeb8cfeb |
42 | $self->dbh->do("RELEASE SAVEPOINT $name"); |
adb3554a |
43 | } |
44 | |
45 | sub _svp_rollback { |
eeb8cfeb |
46 | my ($self, $name) = @_; |
adb3554a |
47 | |
eeb8cfeb |
48 | $self->dbh->do("ROLLBACK TO SAVEPOINT $name") |
adb3554a |
49 | } |
f797e89e |
50 | |
106d5f3b |
51 | sub 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 | |
56 | sub 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 |
62 | sub _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 |
73 | sub _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 |
79 | 1; |
80 | |
75d07914 |
81 | =head1 NAME |
843f8ecd |
82 | |
83 | DBIx::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 | |
93 | This class implements autoincrements for MySQL. |
94 | |
95 | =head1 AUTHORS |
96 | |
97 | Matt S. Trout <mst@shadowcatsystems.co.uk> |
98 | |
99 | =head1 LICENSE |
100 | |
101 | You may distribute this code under the same terms as Perl itself. |
102 | |
103 | =cut |