4eefc9d7b33f58938bf185f77118fd9ddf85cf37
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker / MySQL.pm
1 package # Hide from PAUSE
2   DBIx::Class::SQLMaker::MySQL;
3
4 use base qw( DBIx::Class::SQLMaker );
5 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
6 use namespace::clean;
7
8 #
9 # MySQL does not understand the standard INSERT INTO $table DEFAULT VALUES
10 # Adjust SQL here instead
11 #
12 sub insert {
13   my $self = shift;
14
15   my $table = $_[0];
16   $table = $self->_quote($table);
17
18   if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) {
19     return "INSERT INTO ${table} () VALUES ()"
20   }
21
22   return $self->SUPER::insert (@_);
23 }
24
25 # Allow STRAIGHT_JOIN's
26 sub _generate_join_clause {
27     my ($self, $join_type) = @_;
28
29     if( $join_type && $join_type =~ /^STRAIGHT\z/i ) {
30         return ' STRAIGHT_JOIN '
31     }
32
33     return $self->SUPER::_generate_join_clause( $join_type );
34 }
35
36 # LOCK IN SHARE MODE
37 my $for_syntax = {
38    update => 'FOR UPDATE',
39    shared => 'LOCK IN SHARE MODE'
40 };
41
42 sub _lock_select {
43    my ($self, $type) = @_;
44
45    my $sql = $for_syntax->{$type} || croak "Unknown SELECT .. FOR type '$type' requested";
46
47    return " $sql";
48 }
49
50 1;