Skip to content

Commit 65d233f

Browse files
Matheus Degiovanimbeccati
Matheus Degiovani
authored andcommitted
Fixed bug #64037 (wrong value returned when using a negative numeric field equal to the scale)
1 parent 1c623e3 commit 65d233f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

ext/pdo_firebird/firebird_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{
344344
if (n >= 0) {
345345
*len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d.%0*" LL_MASK "d",
346346
n / f, -var->sqlscale, n % f);
347-
} else if (n < -f) {
347+
} else if (n <= -f) {
348348
*len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d.%0*" LL_MASK "d",
349349
n / f, -var->sqlscale, -n % f);
350350
} else {

ext/pdo_firebird/tests/bug_64037.phpt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Bug #64037 Firebird return wrong value for numeric field
3+
--SKIPIF--
4+
<?php extension_loaded("pdo_firebird") or die("skip"); ?>
5+
<?php function_exists("ibase_query") or die("skip"); ?>
6+
--FILE--
7+
<?php
8+
9+
require("testdb.inc");
10+
11+
$dbh = new PDO("firebird:dbname=$test_base",$user,$password) or die;
12+
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
13+
$value = '2';
14+
@$dbh->exec('DROP TABLE price');
15+
$dbh->exec("CREATE TABLE PRICE (ID INTEGER NOT NULL, TEXT VARCHAR(10), COST NUMERIC(15, 2))");
16+
$dbh->exec("INSERT INTO PRICE (ID, TEXT, COST) VALUES (1, 'test', -1.0)");
17+
$dbh->exec("INSERT INTO PRICE (ID, TEXT, COST) VALUES (2, 'test', -0.99)");
18+
$dbh->exec("INSERT INTO PRICE (ID, TEXT, COST) VALUES (3, 'test', -1.01)");
19+
20+
$dbh->commit();
21+
22+
$query = "SELECT * from price order by ID";
23+
$stmt = $dbh->prepare($query);
24+
$stmt->execute();
25+
$rows = $stmt->fetchAll();
26+
var_dump($rows[0]['COST']);
27+
var_dump($rows[1]['COST']);
28+
var_dump($rows[2]['COST']);
29+
30+
31+
$stmt = $dbh->prepare('DELETE FROM price');
32+
$stmt->execute();
33+
34+
$dbh->commit();
35+
36+
$dbh->exec('DROP TABLE price');
37+
38+
unset($stmt);
39+
unset($dbh);
40+
41+
?>
42+
--EXPECT--
43+
string(5) "-1.00"
44+
string(5) "-0.99"
45+
string(5) "-1.01"

0 commit comments

Comments
 (0)