On Tue, 24 Jun 2003 14:05:03 +0100 Robbie Armour <[EMAIL PROTECTED]> wrote:

> The data's definitely wrong - eg "select concat('fred', t1) from
> test gives "fred0.44".   I first noticed the problem printing eg
> $r->[1] from a fetch in Perl.  It comes out the same either to
> STDOUT or on a Web page.

>> From: Tim Bunce <[EMAIL PROTECTED]>
>> To: Robbie Armour <[EMAIL PROTECTED]>
>> CC: [EMAIL PROTECTED]
>> Subject: Re: Rounding errors storing numbers in MySQL text fields
>> using DBI
>> Date: Tue, 24 Jun 2003 12:16:20 +0100
>>
>> On Tue, Jun 24, 2003 at 03:23:08AM +0100, Robbie Armour wrote:
>>> $qst = $dbh->prepare("insert into test (t1) values (?)");
>>> $qst->execute(0.4444);
>>> $qst->execute('0.3333');
>>>      Binding parameters: insert into test (t1) values (0.4444)
>>>      Binding parameters: insert into test (t1) values (0.3333)
>>>
>>> mysql> select * from test;
>>> +------+
>>> | t1   |
>>> +------+
>>> | 0.44 |
>>> | 0.33 |
>>> +------+

Once a placeholder has been tagged with a type (number in this case),
the type is remembered for the life of the statement.  As a result
'0.3333' is pasted into the SQL as if it is a number.
To test my theory, please try the following sequences in separate
runs:

  # Run 1
  $qst -> execute( "xyz" );
  $qst -> execute( 0.4444 );
  $qst -> execute( 0.3333 );

  # Run 2
  $qst->execute( '0.4444' );
  $qst->execute( 0.3333 );
  
-- 
Mac :})
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

Reply via email to