Skip to content

Commit 09d1a6c

Browse files
committed
Fix #78855: Native PHP types in database fetches - float was added
1 parent 8876a58 commit 09d1a6c

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

‎ext/pgsql/pgsql.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#define INT8OID 20
7070
#define TEXTOID 25
7171
#define OIDOID 26
72+
#define FLOAT4OID 700
73+
#define FLOAT8OID 701
7274

7375
#if ZEND_LONG_MAX < UINT_MAX
7476
#define PGSQL_RETURN_OID(oid) do { \
@@ -2542,6 +2544,18 @@ static inline void php_pgsql_get_field_value(zval *value, PGresult *pgsql_result
25422544
case BOOLOID:
25432545
ZVAL_BOOL(value, *element == 't');
25442546
break;
2547+
case FLOAT4OID:
2548+
case FLOAT8OID:
2549+
if (element_len == sizeof("Infinity") - 1 && strcmp(element, "Infinity") == 0) {
2550+
ZVAL_DOUBLE(value, ZEND_INFINITY);
2551+
} else if (element_len == sizeof("-Infinity") - 1 && strcmp(element, "-Infinity") == 0) {
2552+
ZVAL_DOUBLE(value, -ZEND_INFINITY);
2553+
} else if (element_len == sizeof("NaN") - 1 && strcmp(element, "NaN") == 0) {
2554+
ZVAL_DOUBLE(value, ZEND_NAN);
2555+
} else {
2556+
ZVAL_DOUBLE(value, zend_strtod(element, NULL));
2557+
}
2558+
break;
25452559
case OIDOID:
25462560
case INT2OID:
25472561
case INT4OID:

‎ext/pgsql/tests/bug78855.phpt

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ include 'config.inc';
1212

1313
$db = pg_connect($conn_str);
1414

15-
$res = pg_query($db, "SELECT null, true, false, 1::smallint, 2::int, 3::oid, 'text', '\\x3031'::bytea");
15+
$res = pg_query($db, "SELECT null, true, false, 1::smallint, 2::int, 3::oid, 'text', '\\x3031'::bytea, 1.1::real, 1.2::float, 'Infinity'::float, '-Infinity'::float, 'NaN'::float");
1616
var_dump(pg_fetch_array($res, 0, PGSQL_NUM));
1717
var_dump(pg_fetch_array($res, 0, PGSQL_NUM|PGSQL_TYPED));
1818

1919
var_dump(pg_fetch_all($res, PGSQL_NUM));
2020
var_dump(pg_fetch_all($res, PGSQL_NUM|PGSQL_TYPED));
2121

2222
?>
23-
--EXPECTF--
24-
array(8) {
23+
--EXPECT--
24+
array(13) {
2525
[0]=>
2626
NULL
2727
[1]=>
@@ -38,8 +38,18 @@ array(8) {
3838
string(4) "text"
3939
[7]=>
4040
string(6) "\x3031"
41+
[8]=>
42+
string(3) "1.1"
43+
[9]=>
44+
string(3) "1.2"
45+
[10]=>
46+
string(8) "Infinity"
47+
[11]=>
48+
string(9) "-Infinity"
49+
[12]=>
50+
string(3) "NaN"
4151
}
42-
array(8) {
52+
array(13) {
4353
[0]=>
4454
NULL
4555
[1]=>
@@ -56,10 +66,20 @@ array(8) {
5666
string(4) "text"
5767
[7]=>
5868
string(2) "01"
69+
[8]=>
70+
float(1.1)
71+
[9]=>
72+
float(1.2)
73+
[10]=>
74+
float(INF)
75+
[11]=>
76+
float(-INF)
77+
[12]=>
78+
float(NAN)
5979
}
6080
array(1) {
6181
[0]=>
62-
array(8) {
82+
array(13) {
6383
[0]=>
6484
NULL
6585
[1]=>
@@ -76,11 +96,21 @@ array(1) {
7696
string(4) "text"
7797
[7]=>
7898
string(6) "\x3031"
99+
[8]=>
100+
string(3) "1.1"
101+
[9]=>
102+
string(3) "1.2"
103+
[10]=>
104+
string(8) "Infinity"
105+
[11]=>
106+
string(9) "-Infinity"
107+
[12]=>
108+
string(3) "NaN"
79109
}
80110
}
81111
array(1) {
82112
[0]=>
83-
array(8) {
113+
array(13) {
84114
[0]=>
85115
NULL
86116
[1]=>
@@ -97,5 +127,15 @@ array(1) {
97127
string(4) "text"
98128
[7]=>
99129
string(2) "01"
130+
[8]=>
131+
float(1.1)
132+
[9]=>
133+
float(1.2)
134+
[10]=>
135+
float(INF)
136+
[11]=>
137+
float(-INF)
138+
[12]=>
139+
float(NAN)
100140
}
101141
}

0 commit comments

Comments
 (0)