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