From: Peter Rabbitson Date: Sun, 7 Jun 2009 22:59:21 +0000 (+0000) Subject: Add mysql empty insert SQL override X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=87aa29e2b0123213230b69a61c481deff90a4efd;p=dbsrgits%2FDBIx-Class-Historic.git Add mysql empty insert SQL override Make SQLAHacks parts loadable at runtime via ensure_class_loaded --- diff --git a/lib/DBIx/Class/SQLAHacks/MySQL.pm b/lib/DBIx/Class/SQLAHacks/MySQL.pm new file mode 100644 index 0000000..9b4d0be --- /dev/null +++ b/lib/DBIx/Class/SQLAHacks/MySQL.pm @@ -0,0 +1,24 @@ +package # Hide from PAUSE + DBIx::Class::SQLAHacks::MySQL; + +use base qw( DBIx::Class::SQLAHacks ); +use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; + +# +# MySQL does not understand the standard INSERT INTO $table DEFAULT VALUES +# Adjust SQL here instead +# +sub insert { + my $self = shift; + + my $table = $_[0]; + $table = $self->_quote($table) unless ref($table); + + if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) { + return "INSERT INTO ${table} () VALUES ()" + } + + return $self->SUPER::insert (@_); +} + +1; diff --git a/lib/DBIx/Class/SQLAHacks/OracleJoins.pm b/lib/DBIx/Class/SQLAHacks/OracleJoins.pm index f02a913..4b5efba 100644 --- a/lib/DBIx/Class/SQLAHacks/OracleJoins.pm +++ b/lib/DBIx/Class/SQLAHacks/OracleJoins.pm @@ -2,7 +2,7 @@ package # Hide from PAUSE DBIx::Class::SQLAHacks::OracleJoins; use base qw( DBIx::Class::SQLAHacks ); -use Carp::Clan qw/^DBIx::Class/; +use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; sub select { my ($self, $table, $fields, $where, $order, @rest) = @_; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index e96dece..939e2ad 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -7,7 +7,6 @@ use strict; use warnings; use Carp::Clan qw/^DBIx::Class/; use DBI; -use DBIx::Class::SQLAHacks; use DBIx::Class::Storage::DBI::Cursor; use DBIx::Class::Storage::Statistics; use Scalar::Util qw/blessed weaken/; @@ -603,6 +602,7 @@ sub sql_maker { my ($self) = @_; unless ($self->_sql_maker) { my $sql_maker_class = $self->sql_maker_class; + $self->ensure_class_loaded ($sql_maker_class); $self->_sql_maker($sql_maker_class->new( $self->_sql_maker_args )); } return $self->_sql_maker; diff --git a/lib/DBIx/Class/Storage/DBI/mysql.pm b/lib/DBIx/Class/Storage/DBI/mysql.pm index 77aadff..221548a 100644 --- a/lib/DBIx/Class/Storage/DBI/mysql.pm +++ b/lib/DBIx/Class/Storage/DBI/mysql.pm @@ -5,7 +5,7 @@ use warnings; use base qw/DBIx::Class::Storage::DBI::MultiColumnIn/; -# __PACKAGE__->load_components(qw/PK::Auto/); +__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::MySQL'); sub with_deferred_fk_checks { my ($self, $sub) = @_;