com php-src: Fixed bug #64037 (wrong value returned when using a negative numeric field equal to the scale): ext/pdo_firebird/firebird _statement.c
ext/pdo_firebird/tests/bug_6403 7.phpt
| From: | Matteo Beccati | Date: | Fri, 31 May 2013 12:30:51 +0000 |
| Subject: | com php-src: Fixed bug #64037 (wrong value returned when using a negative numeric field equal to the scale): ext/pdo_firebird/firebird _statement.c ext/pdo_firebird/tests/bug_6403 7.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-72268@lists.php.net to get a copy of this message | ||
Commit: 65d233f06c6e274f9559880a7c187b35932b1918
Author: Matheus Degiovani <matheus@gigatron.com.br> Fri, 22 Mar 2013 10:24:07 -0300
Committer: Matteo Beccati <matteo@beccati.com> Fri, 31 May 2013 14:30:51 +0200
Parents: 1c623e3b07128e78362911ff5754e7eee57fa8bb
Branches: PHP-5.3 PHP-5.4 PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=65d233f06c6e274f9559880a7c187b35932b1918
Log:
Fixed bug #64037 (wrong value returned when using a negative numeric field equal to the scale)
Bugs:
https://bugs.php.net/64037
Changed paths:
M ext/pdo_firebird/firebird_statement.c
A ext/pdo_firebird/tests/bug_64037.phpt
Diff:
diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c
index 5c3e435..ffe9b3c 100644
--- a/ext/pdo_firebird/firebird_statement.c
+++ b/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 {
diff --git a/ext/pdo_firebird/tests/bug_64037.phpt b/ext/pdo_firebird/tests/bug_64037.phpt
new file mode 100644
index 0000000..f7b53e5
--- /dev/null
+++ b/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"
\ No newline at end of file