From: Rafael Kitover Date: Sat, 6 Feb 2010 12:35:31 +0000 (+0000) Subject: move Firebird ODBC override for RETURNING to a SQLAHacks class X-Git-Tag: v0.08121~73^2~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1696e04ff9589eabb5d6bdece54f2284003e6122;p=dbsrgits%2FDBIx-Class.git move Firebird ODBC override for RETURNING to a SQLAHacks class --- diff --git a/Makefile.PL b/Makefile.PL index 0dcb502..1574146 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -39,7 +39,7 @@ requires 'MRO::Compat' => '0.09'; requires 'Module::Find' => '0.06'; requires 'Path::Class' => '0.16'; requires 'Scope::Guard' => '0.03'; -requires 'SQL::Abstract' => '1.60'; +requires 'SQL::Abstract' => '1.61'; requires 'SQL::Abstract::Limit' => '0.13'; requires 'Sub::Name' => '0.04'; requires 'Data::Dumper::Concise' => '1.000'; @@ -128,6 +128,11 @@ my %force_requires_if_author = ( 'DateTime::Format::Strptime' => 0, ) : () , + grep $_, @ENV{qw/DBICTEST_FIREBIRD_DSN DBICTEST_FIREBIRD_ODBC_DSN/} + ? ( + 'DateTime::Format::Strptime' => 0, + ) : () + , ); #************************************************************************# # Make ABSOLUTELY SURE that nothing on the list above is a real require, # diff --git a/lib/DBIx/Class/SQLAHacks/ODBC/Firebird.pm b/lib/DBIx/Class/SQLAHacks/ODBC/Firebird.pm new file mode 100644 index 0000000..b6697e7 --- /dev/null +++ b/lib/DBIx/Class/SQLAHacks/ODBC/Firebird.pm @@ -0,0 +1,24 @@ +package # Hide from PAUSE + DBIx::Class::SQLAHacks::ODBC::Firebird; + +use strict; +use warnings; +use base qw( DBIx::Class::SQLAHacks ); +use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; + +sub insert { + my $self = shift; + my ($table, $vals, $opts) = @_; + +# Quoting RETURNING values breaks the Firebird ODBC driver, so we convert to +# scalarref with unquoted values. + my $returning = $opts->{returning}; + + if ($returning && ref $returning eq 'ARRAY') { + $opts->{returning} = \join ', ' => @$returning; + } + + return $self->next::method(@_); +} + +1; diff --git a/lib/DBIx/Class/Storage/DBI/InterBase.pm b/lib/DBIx/Class/Storage/DBI/InterBase.pm index 0d92cb3..f019ebb 100644 --- a/lib/DBIx/Class/Storage/DBI/InterBase.pm +++ b/lib/DBIx/Class/Storage/DBI/InterBase.pm @@ -16,8 +16,6 @@ sub _prep_for_execute { my $self = shift; my ($op, $extra_bind, $ident, $args) = @_; - my ($sql, $bind) = $self->next::method (@_); - if ($op eq 'insert') { my @pk = $ident->primary_columns; my %pk; @@ -36,24 +34,14 @@ sub _prep_for_execute { } $ident->columns; if (@auto_inc_cols) { - my $auto_inc_cols = - join ', ', - map $self->_quote_column_for_returning($_), @auto_inc_cols; - - $sql .= " RETURNING ($auto_inc_cols)"; + $args->[1]{returning} = \@auto_inc_cols; $self->_auto_incs([]); $self->_auto_incs->[0] = \@auto_inc_cols; } } - return ($sql, $bind); -} - -sub _quote_column_for_returning { - my ($self, $col) = @_; - - return $self->sql_maker->_quote($col); + return $self->next::method(@_); } sub _execute { diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm index d5f2335..b5eefa3 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm @@ -17,10 +17,7 @@ that module for details. =cut -# RETURNING ("foo") is broken in ODBC, but RETURNING (foo) works -sub _quote_column_for_returning { - return $_[1]; -} +__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::ODBC::Firebird'); sub datetime_parser_type { __PACKAGE__ }