[Dbix-class] data precision question

Martin J. Evans martin.evans at easysoft.com
Mon Dec 12 09:54:49 GMT 2011


On 09/12/11 17:44, Alan Humphrey wrote:
> Hi all –
>
> I’ve got a MSSQL database being accessed through ODBC. Several of the columns in the database use a datatype of ‘money’. When I query the database directly those fields come back with 4 digits of precision.
>
> My problem: by the time the data gets back to me via the resultset the column data has been rounded to 2 digits of precision.
>
> This problem persists whether or not I specify a data type in the Result definition.
>
> Any thoughts? Would changing the data type in the MSSQL column definition help?
>
> Thanks!
>
> -Alan

I'm not using dbic but with DBD::ODBC I have no problems getting precision 4 money data back.

isql -v sqlserver sa xxxx
SQL> create table m (a money);
SQLRowCount returns -1
SQL> insert into m values(1.1234);
SQLRowCount returns 1
SQL> insert into m values(2.34567);
SQLRowCount returns 1
SQL> select * from m;
+----------------------+
| a                    |
+----------------------+
| 1.1234               |
| 2.3457               |
+----------------------+
SQLRowCount returns -1
2 rows fetched

perl -le 'use DBI; my $h = DBI->connect("dbi:ODBC:DSN=sqlserver","sa", "xxx"); my $r = $h->selectall_arrayref(q/select * from m/); use Data::Dumper;print Dumper($r);'

$VAR1 = [
           [
             '1.1234'
           ],
           [
             '2.3457'
           ]
         ];

Of course, it may depend on your ODBC driver. You didn't say which one you are using.

Martin
-- 
Martin J. Evans
Easysoft Limited
http://www.easysoft.com



More information about the DBIx-Class mailing list