added with_deferred_fk_checks functionality to storage
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / mysql.pm
1 package DBIx::Class::Storage::DBI::mysql;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class::Storage::DBI/;
7
8 # __PACKAGE__->load_components(qw/PK::Auto/);
9
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
18 sub _dbh_last_insert_id {
19   my ($self, $dbh, $source, $col) = @_;
20   $dbh->{mysql_insertid};
21 }
22
23 sub sqlt_type {
24   return 'MySQL';
25 }
26
27 sub _svp_begin {
28     my ($self, $name) = @_;
29
30     $self->dbh->do("SAVEPOINT $name");
31 }
32
33 sub _svp_release {
34     my ($self, $name) = @_;
35
36     $self->dbh->do("RELEASE SAVEPOINT $name");
37 }
38
39 sub _svp_rollback {
40     my ($self, $name) = @_;
41
42     $self->dbh->do("ROLLBACK TO SAVEPOINT $name")
43 }
44  
45 sub is_replicating {
46     my $status = shift->dbh->selectrow_hashref('show slave status');
47     return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
48 }
49
50 sub lag_behind_master {
51     return shift->dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
52 }
53
54 1;
55
56 =head1 NAME
57
58 DBIx::Class::Storage::DBI::mysql - Automatic primary key class for MySQL
59
60 =head1 SYNOPSIS
61
62   # In your table classes
63   __PACKAGE__->load_components(qw/PK::Auto Core/);
64   __PACKAGE__->set_primary_key('id');
65
66 =head1 DESCRIPTION
67
68 This class implements autoincrements for MySQL.
69
70 =head1 AUTHORS
71
72 Matt S. Trout <mst@shadowcatsystems.co.uk>
73
74 =head1 LICENSE
75
76 You may distribute this code under the same terms as Perl itself.
77
78 =cut