1 package DBIx::Class::Storage::DBI::mysql;
7 DBIx::Class::Storage::DBI::MultiColumnIn
8 DBIx::Class::Storage::DBI::AmbiguousGlob
9 DBIx::Class::Storage::DBI
13 __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL');
15 sub with_deferred_fk_checks {
16 my ($self, $sub) = @_;
18 $self->_do_query('SET FOREIGN_KEY_CHECKS = 0');
20 $self->_do_query('SET FOREIGN_KEY_CHECKS = 1');
23 sub connect_call_set_strict_mode {
26 # the @@sql_mode puts back what was previously set on the session handle
27 $self->_do_query(q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|);
28 $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|);
31 sub _dbh_last_insert_id {
32 my ($self, $dbh, $source, $col) = @_;
33 $dbh->{mysql_insertid};
36 # we need to figure out what mysql version we're running
40 unless ($self->_sql_maker) {
41 my $maker = $self->next::method (@_);
43 # mysql 3 does not understand a bare JOIN
44 my $mysql_ver = $self->_get_dbh->get_info(18);
45 $maker->{_default_jointype} = 'INNER' if $mysql_ver =~ /^3/;
48 return $self->_sql_maker;
56 my ($self, $name) = @_;
58 $self->_get_dbh->do("SAVEPOINT $name");
62 my ($self, $name) = @_;
64 $self->_get_dbh->do("RELEASE SAVEPOINT $name");
68 my ($self, $name) = @_;
70 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
74 my $status = shift->_get_dbh->selectrow_hashref('show slave status');
75 return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
78 sub lag_behind_master {
79 return shift->_get_dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
82 # MySql can not do subquery update/deletes, only way is slow per-row operations.
83 # This assumes you have set proper transaction isolation and use innodb.
84 sub _subq_update_delete {
85 return shift->_per_row_update_delete (@_);
92 DBIx::Class::Storage::DBI::mysql - Storage::DBI class implementing MySQL specifics
96 Storage::DBI autodetects the underlying MySQL database, and re-blesses the
97 C<$storage> object into this class.
99 my $schema = MyDb::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } );
103 This class implements MySQL specific bits of L<DBIx::Class::Storage::DBI>.
105 It also provides a one-stop on-connect macro C<set_strict_mode> which sets
106 session variables such that MySQL behaves more predictably as far as the
107 SQL standard is concerned.
111 See L<DBIx::Class/CONTRIBUTORS>
115 You may distribute this code under the same terms as Perl itself.