Majorly cleanup $rs->update/delete (no $rs-aware code should be in ::Storages)
[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
6 #
7 # MySQL does not understand the standard INSERT INTO $table DEFAULT VALUES
8 # Adjust SQL here instead
9 #
10 sub insert {
11   my $self = shift;
12
13   if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) {
14     my $table = $self->_quote($_[0]);
15     return "INSERT INTO ${table} () VALUES ()"
16   }
17
18   return $self->next::method (@_);
19 }
20
21 # Allow STRAIGHT_JOIN's
22 sub _generate_join_clause {
23     my ($self, $join_type) = @_;
24
25     if( $join_type && $join_type =~ /^STRAIGHT\z/i ) {
26         return ' STRAIGHT_JOIN '
27     }
28
29     return $self->next::method($join_type);
30 }
31
32 # LOCK IN SHARE MODE
33 my $for_syntax = {
34    update => 'FOR UPDATE',
35    shared => 'LOCK IN SHARE MODE'
36 };
37
38 sub _lock_select {
39    my ($self, $type) = @_;
40
41    my $sql = $for_syntax->{$type}
42     || $self->throw_exception("Unknown SELECT .. FOR type '$type' requested");
43
44    return " $sql";
45 }
46
47 1;