Skip to content

Commit bdd7711

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-13119 (#13125)
2 parents 36b1695 + f234104 commit bdd7711

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ PDO_FIREBIRD:
7272
. Feature: Add transaction isolation level and mode settings to pdo_firebird.
7373
(SakiTakamachi)
7474
. Added class PdoFirebird. (danack, kocsismate)
75+
. Fix GH-13119 (Changed to convert float and double values ​​into strings using
76+
`H` format). (SakiTakamachi)
7577

7678
PDO_MYSQL:
7779
. Fixed setAttribute and getAttribute. (SakiTakamachi)

ext/pdo_firebird/firebird_statement.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ static int pdo_firebird_stmt_get_col(
463463
break;
464464
case SQL_FLOAT:
465465
/* TODO: Why is this not returned as the native type? */
466-
ZVAL_STR(result, zend_strpprintf(0, "%F", php_get_float_from_sqldata(var->sqldata)));
466+
ZVAL_STR(result, zend_strpprintf_unchecked(0, "%.8H", php_get_float_from_sqldata(var->sqldata)));
467467
break;
468468
case SQL_DOUBLE:
469469
/* TODO: Why is this not returned as the native type? */
470-
ZVAL_STR(result, zend_strpprintf(0, "%F", php_get_double_from_sqldata(var->sqldata)));
470+
ZVAL_STR(result, zend_strpprintf_unchecked(0, "%.16H", php_get_double_from_sqldata(var->sqldata)));
471471
break;
472472
#ifdef SQL_BOOLEAN
473473
case SQL_BOOLEAN:

ext/pdo_firebird/tests/gh10908.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ Array
8383

8484
Array
8585
(
86-
[DBL] => 1.000000
87-
[0] => 1.000000
86+
[DBL] => 1
87+
[0] => 1
8888
)
8989

9090
Array
@@ -107,10 +107,10 @@ Array
107107
[1] => ABC
108108
[NUM] => 12.340
109109
[2] => 12.340
110-
[DBL] => 1.000000
111-
[3] => 1.000000
112-
[FLT] => 2.000000
113-
[4] => 2.000000
110+
[DBL] => 1
111+
[3] => 1
112+
[FLT] => 2
113+
[4] => 2
114114
[TS] => 2023-03-24 17:39:00
115115
[5] => 2023-03-24 17:39:00
116116
[MYDATE] => 2023-03-24

ext/pdo_firebird/tests/gh13119.phpt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--TEST--
2+
GH-13119 (float, double value is incorrect)
3+
--EXTENSIONS--
4+
pdo_firebird
5+
--SKIPIF--
6+
<?php require('skipif.inc'); ?>
7+
--XLEAK--
8+
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
9+
See https://github.com/FirebirdSQL/firebird/issues/7849
10+
--FILE--
11+
<?php
12+
13+
require("testdb.inc");
14+
15+
$dbh = getDbConnection();
16+
$dbh->exec('CREATE TABLE gh13119 (f_val FLOAT, d_val DOUBLE PRECISION)');
17+
18+
$dbh->exec('INSERT INTO gh13119 VALUES (0.1, 0.1)');
19+
$dbh->exec('INSERT INTO gh13119 VALUES (0.0000000000000001, 0.0000000000000001)');
20+
$dbh->exec('INSERT INTO gh13119 VALUES (12.000000, 12.00000000000000)');
21+
$dbh->exec('INSERT INTO gh13119 VALUES (12.000001, 12.00000000000001)');
22+
$dbh->exec('INSERT INTO gh13119 VALUES (12.345678, 12.34567890123456)');
23+
$dbh->exec('INSERT INTO gh13119 VALUES (0.0000000000000000012345678, 0.000000000000000001234567890123456)');
24+
25+
$stmt = $dbh->query('select * from gh13119');
26+
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
27+
?>
28+
--CLEAN--
29+
<?php
30+
require 'testdb.inc';
31+
$dbh = getDbConnection();
32+
@$dbh->exec('DROP TABLE gh13119');
33+
unset($dbh);
34+
?>
35+
--EXPECT--
36+
array(6) {
37+
[0]=>
38+
array(2) {
39+
["F_VAL"]=>
40+
string(3) "0.1"
41+
["D_VAL"]=>
42+
string(3) "0.1"
43+
}
44+
[1]=>
45+
array(2) {
46+
["F_VAL"]=>
47+
string(7) "1.0E-16"
48+
["D_VAL"]=>
49+
string(7) "1.0E-16"
50+
}
51+
[2]=>
52+
array(2) {
53+
["F_VAL"]=>
54+
string(2) "12"
55+
["D_VAL"]=>
56+
string(2) "12"
57+
}
58+
[3]=>
59+
array(2) {
60+
["F_VAL"]=>
61+
string(9) "12.000001"
62+
["D_VAL"]=>
63+
string(17) "12.00000000000001"
64+
}
65+
[4]=>
66+
array(2) {
67+
["F_VAL"]=>
68+
string(9) "12.345678"
69+
["D_VAL"]=>
70+
string(17) "12.34567890123456"
71+
}
72+
[5]=>
73+
array(2) {
74+
["F_VAL"]=>
75+
string(13) "1.2345678E-18"
76+
["D_VAL"]=>
77+
string(21) "1.234567890123456E-18"
78+
}
79+
}

0 commit comments

Comments
 (0)