Skip Menu |

This queue is for tickets about the DBI CPAN distribution.

Report information
The Basics
Id: 46231
Status: rejected
Priority: 0/
Queue: DBI

People
Owner: Nobody in particular
Requestors: notbenh [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 1.607
  • 1.608
Fixed in: (no value)



Subject: DBI does not seem to want to handle floats as a numeric type
[TEST] #!/usr/bin/perl; use strict; use warnings; use Test::Most qw{no_plan}; use DBI qw{SQL_FLOAT}; ok( my $d = DBI->connect('dbi:mysql:test:localhost','ben','' ) ); ok( $d->do(q{CREATE TABLE float_as_string (value FLOAT)}) ); ok( $d->do(q{TRUNCATE float_as_string }) ); END{ ok( $d->do(q{DROP TABLE float_as_string}) ); }; my $v = 6.12; ok( $d->do(q{INSERT INTO float_as_string SET value = ?}, {}, $v) ); eq_or_diff( $d->quote ($v), $v, q{what does quote look like?}, ); eq_or_diff( $d->quote($v, SQL_FLOAT ), $v, q{what does quote look like?}, ); eq_or_diff( $d->selectall_arrayref(q{SELECT * FROM float_as_string}, {Slice=> {}}), [{value => $v}], q{it's there}, ); eq_or_diff( $d->selectall_arrayref(q{SELECT * FROM float_as_string WHERE value = ?}, {Slice=>{}}, $v), [{value => $v}], q{select works?}, ); eq_or_diff( $d->selectall_arrayref(q{SELECT * FROM float_as_string WHERE value = ?}, {Slice=>{}}, $v+0), [{value => $v}], q{select works with +0?}, ); [OUTPUT] ok 1 ok 2 ok 3 ok 4 not ok 5 - what does quote look like? # Failed test 'what does quote look like?' # at /home/benh/mirror/benh/src/test/dbi_float_string.t line 20. # +---+--------+----------+ # | Ln|Got |Expected | # +---+--------+----------+ # * 1|'6.12' |6.12 * # +---+--------+----------+ ok 6 - what does quote look like? ok 7 - it's there not ok 8 - select works? # Failed test 'select works?' # at /home/benh/mirror/benh/src/test/dbi_float_string.t line 37. # +----+-----+----+---------------------+ # | Elt|Got | Elt|Expected | # +----+-----+----+---------------------+ # * 0|[] * 0|[ * # | | * 1| { * # | | * 2| value => '6.12' * # | | * 3| } * # | | * 4|] * # +----+-----+----+---------------------+ not ok 9 - select works with +0? # Failed test 'select works with +0?' # at /home/benh/mirror/benh/src/test/dbi_float_string.t line 42. # +----+-----+----+---------------------+ # | Elt|Got | Elt|Expected | # +----+-----+----+---------------------+ # * 0|[] * 0|[ * # | | * 1| { * # | | * 2| value => '6.12' * # | | * 3| } * # | | * 4|] * # +----+-----+----+---------------------+ ok 10 1..10 # Looks like you failed 3 tests of 10.
From: NOTBENH [...] cpan.org
I should add that if I change the col type from FLOAT to CHAR(5) then the select tests work, though test #5 (numeric quote) fails as expected. On Tue May 19 18:13:47 2009, http://notbenh.myopenid.com/ wrote: Show quoted text
> [TEST] > #!/usr/bin/perl; > > use strict; > use warnings; > > use Test::Most qw{no_plan}; > use DBI qw{SQL_FLOAT}; > > ok( my $d = DBI->connect('dbi:mysql:test:localhost','ben','' ) ); > > ok( $d->do(q{CREATE TABLE float_as_string (value FLOAT)}) ); > ok( $d->do(q{TRUNCATE float_as_string }) ); > END{ > ok( $d->do(q{DROP TABLE float_as_string}) ); > }; > > my $v = 6.12; > ok( $d->do(q{INSERT INTO float_as_string SET value = ?}, {}, $v) ); > > eq_or_diff( > $d->quote > ($v), > $v, > q{what does quote look like?}, > ); > > eq_or_diff( > $d->quote($v, SQL_FLOAT ), > $v, > q{what does quote look like?}, > ); > > eq_or_diff( > $d->selectall_arrayref(q{SELECT * FROM float_as_string}, {Slice=> > {}}), > [{value => $v}], > q{it's there}, > ); > eq_or_diff( > $d->selectall_arrayref(q{SELECT * FROM float_as_string WHERE value > = ?}, {Slice=>{}}, $v), > [{value => $v}], > q{select works?}, > ); > eq_or_diff( > $d->selectall_arrayref(q{SELECT * FROM float_as_string WHERE value > = ?}, {Slice=>{}}, $v+0), > [{value => $v}], > q{select works with +0?}, > ); > > > [OUTPUT] > ok 1 > ok 2 > ok 3 > ok 4 > not ok 5 - what does quote look like? > # Failed test 'what does quote look like?' > # at /home/benh/mirror/benh/src/test/dbi_float_string.t line 20. > # +---+--------+----------+ > # | Ln|Got |Expected | > # +---+--------+----------+ > # * 1|'6.12' |6.12 * > # +---+--------+----------+ > ok 6 - what does quote look like? > ok 7 - it's there > not ok 8 - select works? > # Failed test 'select works?' > # at /home/benh/mirror/benh/src/test/dbi_float_string.t line 37. > # +----+-----+----+---------------------+ > # | Elt|Got | Elt|Expected | > # +----+-----+----+---------------------+ > # * 0|[] * 0|[ * > # | | * 1| { * > # | | * 2| value => '6.12' * > # | | * 3| } * > # | | * 4|] * > # +----+-----+----+---------------------+ > not ok 9 - select works with +0? > # Failed test 'select works with +0?' > # at /home/benh/mirror/benh/src/test/dbi_float_string.t line 42. > # +----+-----+----+---------------------+ > # | Elt|Got | Elt|Expected | > # +----+-----+----+---------------------+ > # * 0|[] * 0|[ * > # | | * 1| { * > # | | * 2| value => '6.12' * > # | | * 3| } * > # | | * 4|] * > # +----+-----+----+---------------------+ > ok 10 > 1..10 > # Looks like you failed 3 tests of 10.
Not a bug. It's always problematic to compare floats for equality.