Browse Source

Fixed bug #64037 (wrong value returned when using a negative numeric field equal to the scale)

pull/366/head
Matheus Degiovani 14 years ago
committed by Matteo Beccati
parent
commit
65d233f06c
  1. 2
      ext/pdo_firebird/firebird_statement.c
  2. 45
      ext/pdo_firebird/tests/bug_64037.phpt

2
ext/pdo_firebird/firebird_statement.c

@ -344,7 +344,7 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{
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) {
} else if (n <= -f) {
*len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d.%0*" LL_MASK "d",
n / f, -var->sqlscale, -n % f);
} else {

45
ext/pdo_firebird/tests/bug_64037.phpt

@ -0,0 +1,45 @@
--TEST--
Bug #64037 Firebird return wrong value for numeric field
--SKIPIF--
<?php extension_loaded("pdo_firebird") or die("skip"); ?>
<?php function_exists("ibase_query") or die("skip"); ?>
--FILE--
<?php
require("testdb.inc");
$dbh = new PDO("firebird:dbname=$test_base",$user,$password) or die;
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$value = '2';
@$dbh->exec('DROP TABLE price');
$dbh->exec("CREATE TABLE PRICE (ID INTEGER NOT NULL, TEXT VARCHAR(10), COST NUMERIC(15, 2))");
$dbh->exec("INSERT INTO PRICE (ID, TEXT, COST) VALUES (1, 'test', -1.0)");
$dbh->exec("INSERT INTO PRICE (ID, TEXT, COST) VALUES (2, 'test', -0.99)");
$dbh->exec("INSERT INTO PRICE (ID, TEXT, COST) VALUES (3, 'test', -1.01)");
$dbh->commit();
$query = "SELECT * from price order by ID";
$stmt = $dbh->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();
var_dump($rows[0]['COST']);
var_dump($rows[1]['COST']);
var_dump($rows[2]['COST']);
$stmt = $dbh->prepare('DELETE FROM price');
$stmt->execute();
$dbh->commit();
$dbh->exec('DROP TABLE price');
unset($stmt);
unset($dbh);
?>
--EXPECT--
string(5) "-1.00"
string(5) "-0.99"
string(5) "-1.01"
Loading…
Cancel
Save