From: Rafael Kitover Date: Thu, 23 Jul 2009 14:31:08 +0000 (+0000) Subject: fix money columns X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d68f21eedc64910ba75f23a8eff8c60be21ef126;p=dbsrgits%2FDBIx-Class-Historic.git fix money columns --- diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm index 2fde285..6c3483e 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -38,6 +38,20 @@ sub _prep_for_execute { my $self = shift; my ($op, $extra_bind, $ident, $args) = @_; +# cast MONEY values properly + if ($op eq 'insert' || $op eq 'update') { + my $fields = $args->[0]; + my $col_info = $self->_resolve_column_info($ident, [keys %$fields]); + + for my $col (keys %$col_info) { + if ($col_info->{$col}{data_type} eq 'money') { + my $val = $fields->{$col}; + + $fields->{$col} = \['CAST(? AS MONEY)', [ $col => $val ]]; + } + } + } + my ($sql, $bind) = $self->next::method (@_); if ($op eq 'insert') { diff --git a/t/746mssql.t b/t/746mssql.t index 7400698..09f065f 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -12,7 +12,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PA plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test' unless ($dsn && $user); -plan tests => 29; +plan tests => 31; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); @@ -94,11 +94,17 @@ my $rs = $schema->resultset('Money'); my $row; lives_ok { - $row = $rs->create({ amount => \'cast(100.00 as money)' }); + $row = $rs->create({ amount => 100 }); } 'inserted a money value'; is $rs->find($row->id)->amount, '100.00', 'money value round-trip'; +lives_ok { + $row->update({ amount => 200 }); +} 'updated a money value'; + +is $rs->find($row->id)->amount, '200.00', 'updated money value round-trip'; + $schema->storage->dbh_do (sub { my ($storage, $dbh) = @_; eval { $dbh->do("DROP TABLE Owners") };