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