Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fast-path populate for MSSQL MONEY fields #145

Open
wants to merge 1 commit into
base: maint/0.0828xx
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/DBIx/Class/Storage/DBI/MSSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use base qw/
/;
use mro 'c3';

use SQL::Abstract::Classic 'is_literal_value';
use Try::Tiny;
use namespace::clean;

Expand Down Expand Up @@ -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} ]];
}
}
}
}
Expand Down