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.