1 package DBIx::Class::Storage::DBI::mysql;
6 use base qw/DBIx::Class::Storage::DBI::MultiColumnIn/;
8 __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL');
10 sub with_deferred_fk_checks {
11 my ($self, $sub) = @_;
13 $self->_do_query('SET FOREIGN_KEY_CHECKS = 0');
15 $self->_do_query('SET FOREIGN_KEY_CHECKS = 1');
18 sub connect_call_set_ansi_mode {
20 $self->_do_query(q|SET SQL_MODE = 'ANSI,TRADITIONAL'|);
21 $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|);
24 sub _dbh_last_insert_id {
25 my ($self, $dbh, $source, $col) = @_;
26 $dbh->{mysql_insertid};
34 my ($self, $name) = @_;
36 $self->dbh->do("SAVEPOINT $name");
40 my ($self, $name) = @_;
42 $self->dbh->do("RELEASE SAVEPOINT $name");
46 my ($self, $name) = @_;
48 $self->dbh->do("ROLLBACK TO SAVEPOINT $name")
52 my $status = shift->dbh->selectrow_hashref('show slave status');
53 return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
56 sub lag_behind_master {
57 return shift->dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
60 # MySql can not do subquery update/deletes, only way is slow per-row operations.
61 # This assumes you have set proper transaction isolation and use innodb.
62 sub _subq_update_delete {
63 return shift->_per_row_update_delete (@_);
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)
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 ];
83 DBIx::Class::Storage::DBI::mysql - Automatic primary key class for MySQL
87 # In your table classes
88 __PACKAGE__->load_components(qw/PK::Auto Core/);
89 __PACKAGE__->set_primary_key('id');
93 This class implements autoincrements for MySQL.
97 Matt S. Trout <mst@shadowcatsystems.co.uk>
101 You may distribute this code under the same terms as Perl itself.