From 6e34dfe1a477c7dcae699ac5db38e2177963f74d Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 19 May 2022 10:22:28 -0700 Subject: [PATCH] fix fast-path populate for MSSQL MONEY fields http://lists.scsys.co.uk/pipermail/dbix-class/2017-May/012630.html Fix by: Peter Rabbitson --- lib/DBIx/Class/Storage/DBI/MSSQL.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index e54ab69b1..1f584d69f 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -9,6 +9,7 @@ use base qw/ /; use mro 'c3'; +use SQL::Abstract::Classic 'is_literal_value'; use Try::Tiny; use namespace::clean; @@ -43,8 +44,21 @@ sub _prep_for_execute { && $colinfo->{$col}{data_type} =~ /^money\z/i ) { - my $val = $fields->{$col}; - $fields->{$col} = \['CAST(? AS MONEY)', [ $col => $val ]]; + if( + length ref $fields->{$col} + and + my $lit = is_literal_value( $fields->{$col} ) + ) { + # We are being fed a literal value + # Generally there is not much we can do about it, *except* + # in the unambiguous case of a lone bind parameter + $fields->{$col} = \[ 'CAST(? AS MONEY)', @{$lit}[ 1 .. $#$lit ] ] + if $lit->[0] eq '?'; + } + # nonliteral - wrap away + else { + $fields->{$col} = \['CAST(? AS MONEY)', [ $col => $fields->{$col} ]]; + } } } }