X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSQLAHacks.pm;h=a454cd5f6948f8ef6bf8691a2b4bdc66b333724b;hb=1ab6145705e18535e27e538c87a11b9483121f1e;hp=f05970baba13939432f2838fff36ac3e9791bfb2;hpb=1cbd30341b52723431f4ae937df004ba81428619;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index f05970b..a454cd5 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -4,7 +4,28 @@ package # Hide from PAUSE use base qw/SQL::Abstract::Limit/; use strict; use warnings; -use Carp::Clan qw/^DBIx::Class/; +use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; + +BEGIN { + # reinstall the carp()/croak() functions imported into SQL::Abstract + # as Carp and Carp::Clan do not like each other much + no warnings qw/redefine/; + no strict qw/refs/; + for my $f (qw/carp croak/) { + my $orig = \&{"SQL::Abstract::$f"}; + *{"SQL::Abstract::$f"} = sub { + + local $Carp::CarpLevel = 1; # even though Carp::Clan ignores this, $orig will not + + if (Carp::longmess() =~ /DBIx::Class::SQLAHacks::[\w]+\(\) called/) { + __PACKAGE__->can($f)->(@_); + } + else { + $orig->(@_); + } + } + } +} sub new { my $self = shift->SUPER::new(@_); @@ -172,6 +193,14 @@ sub insert { my $self = shift; my $table = shift; $table = $self->_quote($table) unless ref($table); + + # SQLA will emit INSERT INTO $table ( ) VALUES ( ) + # which is sadly understood only by MySQL. Change default behavior here, + # until SQLA2 comes with proper dialect support + if (! $_[0] or (ref $_[0] eq 'HASH' and !keys %{$_[0]} ) ) { + return "INSERT INTO ${table} DEFAULT VALUES" + } + $self->SUPER::insert($table, @_); }