1 package # Hide from PAUSE
2 DBIx::Class::SQLMaker::MySQL;
7 use base qw( DBIx::Class::SQLMaker );
10 # MySQL does not understand the standard INSERT INTO $table DEFAULT VALUES
11 # Adjust SQL here instead
16 if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) {
17 my $table = $self->_quote($_[0]);
18 return "INSERT INTO ${table} () VALUES ()"
21 return $self->next::method (@_);
24 # Allow STRAIGHT_JOIN's
25 sub _generate_join_clause {
26 my ($self, $join_type) = @_;
28 if( $join_type && $join_type =~ /^STRAIGHT\z/i ) {
29 return ' STRAIGHT_JOIN '
32 return $self->next::method($join_type);
35 my $force_double_subq;
36 $force_double_subq = sub {
37 my ($self, $sql) = @_;
39 require Text::Balanced;
43 my ($prefix, $parenthesized);
45 ($parenthesized, $sql, $prefix) = do {
46 # idiotic design - writes to $@ but *DOES NOT* throw exceptions
48 Text::Balanced::extract_bracketed( $sql, '()', qr/[^\(]*/ );
51 # this is how an error is indicated, in addition to crapping in $@
52 last unless $parenthesized;
54 if ($parenthesized =~ $self->{_modification_target_referenced_re}) {
55 # is this a select subquery?
56 if ( $parenthesized =~ /^ \( \s* SELECT \s+ /xi ) {
57 $parenthesized = "( SELECT * FROM $parenthesized `_forced_double_subquery` )";
59 # then drill down until we find it (if at all)
61 $parenthesized =~ s/^ \( (.+) \) $/$1/x;
62 $parenthesized = join ' ', '(', $self->$force_double_subq( $parenthesized ), ')';
66 $new_sql .= $prefix . $parenthesized;
69 return $new_sql . $sql;
75 # short-circuit unless understood identifier
76 return $self->next::method(@_) unless $self->{_modification_target_referenced_re};
78 my ($sql, @bind) = $self->next::method(@_);
80 $sql = $self->$force_double_subq($sql)
81 if $sql =~ $self->{_modification_target_referenced_re};
89 # short-circuit unless understood identifier
90 return $self->next::method(@_) unless $self->{_modification_target_referenced_re};
92 my ($sql, @bind) = $self->next::method(@_);
94 $sql = $self->$force_double_subq($sql)
95 if $sql =~ $self->{_modification_target_referenced_re};
102 update => 'FOR UPDATE',
103 shared => 'LOCK IN SHARE MODE'
107 my ($self, $type) = @_;
109 my $sql = $for_syntax->{$type}
110 || $self->throw_exception("Unknown SELECT .. FOR type '$type' requested");