Edit report at https://bugs.php.net/bug.php?id=64037&edit=1

 ID:                 64037
 Updated by:         mbecc...@php.net
 Reported by:        vberko at mail dot com
 Summary:            Firebird return wrong value for numeric field
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PDO related
 Operating System:   Windows
 PHP Version:        5.4.11
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of math...@gigatron.com.br
Revision: 
http://git.php.net/?p=php-src.git;a=commit;h=65d233f06c6e274f9559880a7c187b35932b1918
Log: Fixed bug #64037 (wrong value returned when using a negative numeric field 
equal to the scale)


Previous Comments:
------------------------------------------------------------------------
[2013-05-30 16:32:54] slavb18 at gmail dot com

may be related problem, but is not fixed by patch "around line 347"

/* procedure text

create or alter procedure TESTPROC
returns (
    RES numeric(15,2))
as
begin
  /* Procedure Text */
  res=15123.23;
  suspend;
end
*/

$q="Select * from testproc";
$sth=$pdo->query($q);
$row=$sth->fetch(PDO::FETCH_ASSOC);
print_r($row);

Outputs random number, like:

Array
(
    [RES] => 1396457606527.04
)


istead of

Array
(
    [RES] => 15123.23
)

------------------------------------------------------------------------
[2013-03-21 20:12:45] matheus at gigatron dot com dot br

Figured out the problem. It's a one character fix on firebird_statement.c, 
around line 347. 

The case when (n < f) must be (n <= f).

                        if (n >= 0) {
                                *len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK 
"d.%0*" LL_MASK "d", 
                                        n / f, -var->sqlscale, n % f);
                        } else if (n <= -f) {
                                *len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK 
"d.%0*" LL_MASK "d",
                                        n / f, -var->sqlscale, -n % f);         
                
                         } else {
                                *len = slprintf(*ptr, CHAR_BUF_LEN, "-0.%0*" 
LL_MASK "d", -var->sqlscale, -n % f);
                        }

If needed by the developers, I'll try and make a patch available.

------------------------------------------------------------------------
[2013-03-21 19:39:29] matheus at gigatron dot com dot br

This still happens on php5.5 beta1. 

Also note that any value other than "-1" (0.99, -1.01, etc) will **not** 
trigger the error.

------------------------------------------------------------------------
[2013-01-21 13:18:01] vberko at mail dot com

Description:
------------
When i store -1 value in a numeric field and i read back, i get -0.00


Test script:
---------------
SET SQL DIALECT 3;
SET NAMES WIN1250;
CREATE DATABASE '127.0.0.1/gds_db:C:\TEST\test2.fdb' USER 'test' PASSWORD 
'test' PAGE_SIZE = 4096 DEFAULT CHARACTER SET WIN1250;
CREATE TABLE PRICE (ID INTEGER NOT NULL, TEXT VARCHAR(10), COST NUMERIC(15, 2));
INSERT INTO PRICE (ID, TEXT, COST) VALUES (2, 'test', -1);

$db=new 
PDO("firebird:dbname=localhost:c:/TEST/test2.fdb","test","test",array());
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);                   
$sql="select id,cost from price where id=2";
$q=$db->query($sql);
$ret=$q->fetchAll();
var_dump($ret);

result:
array(1) { [0]=> array(4) { ["ID"]=> string(1) "2" [0]=> string(1) "2" 
["COST"]=> string(5) "-0.00" [1]=> string(5) "-0.00" } } 

Expected result:
----------------
I get back -0.00 but the right result is -1.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64037&edit=1

Reply via email to