Ditch Carp::Clan for our own thing
[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   my $table = $_[0];
14   $table = $self->_quote($table);
15
16   if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) {
17     return "INSERT INTO ${table} () VALUES ()"
18   }
19
20   return $self->SUPER::insert (@_);
21 }
22
23 # Allow STRAIGHT_JOIN's
24 sub _generate_join_clause {
25     my ($self, $join_type) = @_;
26
27     if( $join_type && $join_type =~ /^STRAIGHT\z/i ) {
28         return ' STRAIGHT_JOIN '
29     }
30
31     return $self->SUPER::_generate_join_clause( $join_type );
32 }
33
34 # LOCK IN SHARE MODE
35 my $for_syntax = {
36    update => 'FOR UPDATE',
37    shared => 'LOCK IN SHARE MODE'
38 };
39
40 sub _lock_select {
41    my ($self, $type) = @_;
42
43    my $sql = $for_syntax->{$type}
44     || $self->throw_exception("Unknown SELECT .. FOR type '$type' requested");
45
46    return " $sql";
47 }
48
49 1;