Re: DB autoExecute(): handling of float values
| From: | Mark Wiesemann | Date: | Thu, 02 Nov 2006 17:49:12 +0000 |
| Subject: | Re: DB autoExecute(): handling of float values | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25698@lists.php.net to get a copy of this message | ||
Markus Ernst wrote:
> Trying to insert a float value with autoExecute():
>
> $data = array(
> 'obj_id' => 3,
> 'price_id' => 5,
> 'amount' => 32.5
> );
> $check = $db->autoExecute('tablename', $data, DB_AUTOQUERY_INSERT);
> var_dump($check);
>
> In the error code I find:
> string(139) "INSERT INTO tablename (obj_id,price_id,amount) VALUES
> (3,5,32,5) [nativecode=1136 ** Column count doesn't match value count at
> row 1]"
>
> So DB seems to change the decimal point in the amount field to a comma,
> but without quoting it, which leads to a broken query syntax.
>
> While the solution is easy - cast the amount to a string - I wonder if
> this is the expected behaviour, and for what reason. It looks like a bug
> to me, but I do not find any such bug report for DB nor MDB2, and it is
> hard to imagine that I was the first one trying to insert a float value
> into a float db field with autoExecute()...
It's a bug in DB that a user of DB_Table some weeks ago noted (and he
said that he will open a bug report for DB; MDB2 is not affected because
of smarter logic for handling of decimals).
If you want to open a bug report:
The error is in executeEmulateQuery() in DB/common.php. The string
concatenation in line 1003
$realquery .= $this->quoteSmart($value);
is responsible for the error (quoteSmart() has the right value, but the
concatenation breaks the query).
Regards,
Mark