xref: /PHP-8.4/ext/pdo_pgsql/tests/float.phpt (revision 6d10a698)
1--TEST--
2PDO PgSQL float value
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
16$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
17$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
18$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
19
20$stmt = $db->query(<<<'SQL'
21select cast(0.4 as float4) as value4,
22cast(0.8 as float8) as value8,
23cast('NaN' as float4) as valuenan,
24cast('Infinity' as float4) as valueinfinity,
25cast('-Infinity' as float4) as valueninfinity
26SQL);
27
28var_dump($stmt->fetchAll());
29var_dump($stmt->getColumnMeta(0));
30var_dump($stmt->getColumnMeta(1));
31var_dump($stmt->getColumnMeta(2));
32var_dump($stmt->getColumnMeta(3));
33var_dump($stmt->getColumnMeta(4));
34?>
35--EXPECT--
36array(1) {
37  [0]=>
38  array(5) {
39    ["value4"]=>
40    float(0.4)
41    ["value8"]=>
42    float(0.8)
43    ["valuenan"]=>
44    float(NAN)
45    ["valueinfinity"]=>
46    float(INF)
47    ["valueninfinity"]=>
48    float(-INF)
49  }
50}
51array(7) {
52  ["pgsql:oid"]=>
53  int(700)
54  ["pgsql:table_oid"]=>
55  int(0)
56  ["native_type"]=>
57  string(6) "float4"
58  ["pdo_type"]=>
59  int(2)
60  ["name"]=>
61  string(6) "value4"
62  ["len"]=>
63  int(4)
64  ["precision"]=>
65  int(-1)
66}
67array(7) {
68  ["pgsql:oid"]=>
69  int(701)
70  ["pgsql:table_oid"]=>
71  int(0)
72  ["native_type"]=>
73  string(6) "float8"
74  ["pdo_type"]=>
75  int(2)
76  ["name"]=>
77  string(6) "value8"
78  ["len"]=>
79  int(8)
80  ["precision"]=>
81  int(-1)
82}
83array(7) {
84  ["pgsql:oid"]=>
85  int(700)
86  ["pgsql:table_oid"]=>
87  int(0)
88  ["native_type"]=>
89  string(6) "float4"
90  ["pdo_type"]=>
91  int(2)
92  ["name"]=>
93  string(8) "valuenan"
94  ["len"]=>
95  int(4)
96  ["precision"]=>
97  int(-1)
98}
99array(7) {
100  ["pgsql:oid"]=>
101  int(700)
102  ["pgsql:table_oid"]=>
103  int(0)
104  ["native_type"]=>
105  string(6) "float4"
106  ["pdo_type"]=>
107  int(2)
108  ["name"]=>
109  string(13) "valueinfinity"
110  ["len"]=>
111  int(4)
112  ["precision"]=>
113  int(-1)
114}
115array(7) {
116  ["pgsql:oid"]=>
117  int(700)
118  ["pgsql:table_oid"]=>
119  int(0)
120  ["native_type"]=>
121  string(6) "float4"
122  ["pdo_type"]=>
123  int(2)
124  ["name"]=>
125  string(14) "valueninfinity"
126  ["len"]=>
127  int(4)
128  ["precision"]=>
129  int(-1)
130}
131