On Sun, 22 Jun 2003, Robbie Armour wrote:
> Hello other DBI Users
>
> I use MySQL text fields as general repositories for code, data etc but find
> that numbers are rounded to two decimal places. This does not happen with a
> similarly constructed Oracle table - eg
>
> my $c = $dbh->prepare("insert into test (t1) values (?)");
> $c->execute(0.4444);
> $c->execute(0.5555);
>
> results in 0.44 and 0.56 being stored in the text field. If field t1 is
> varchar this does not happen.
>
> Has anyone got a fix for this? I know I can kludge it, but I'd rather code
> it straight!
Looks like mysql is doing the rounding iff you are inserting a numeric
value into a text field; varchar(n), and everthing else seem to work
just fine.
mysql> insert into round_test VALUES (.4444);
Query OK, 1 row affected (0.00 sec)
mysql> select * from round_test;
+------+
| t1 |
+------+
| 0.44 |
+------+
1 row in set (0.00 sec)
Try this:
http://www.remotelinux.com/rlippan/DBD-mysql-2.9002.tar.gz
And let me know if you still see the problem with this version. In 2.9002
the default bind type uses quotes even when a number passed to
bind_param(), so I am betting that it will fix your problem.
Also, when you try the above, could you try this:
$c->bind_param(1, 0.4444, DBI::SQL_INTEGER);
$c->execute();
$c->bind_param(1, 0.5555, DBI::SQL_INTEGER);
$c->execute();
and let me know what happens? (should go back to the rounding)
Rudy