xref: /PHP-8.1/ext/pdo_pgsql/tests/bug62498.phpt (revision 1e012ecb)
1--TEST--
2PDO PgSQL Bug #62498 (pdo_pgsql inefficient when getColumnMeta() is used), 64-bit
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11if (PHP_INT_SIZE < 8) die("skip valid for 64-bit only");
12?>
13--FILE--
14<?php
15echo "Begin test...\n";
16
17require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
18$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
19$db->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
20
21// create the table
22$db->exec("CREATE TEMPORARY TABLE bugtest_62498 (int2col INT2, int4col INT4, int8col INT8, stringcol VARCHAR(255), boolcol BOOLEAN, datecol DATE, textcol TEXT, tscol TIMESTAMP, byteacol BYTEA)");
23
24// insert some data
25$statement = $db->prepare("INSERT INTO bugtest_62498 (int2col, int4col, int8col, stringcol, boolcol, datecol, textcol, tscol, byteacol) VALUES (:int2val, :int4val, :int8val, :stringval, :boolval, :dateval, :textval, :tsval, :byteaval)");
26$vals = array(
27    "int2val" => "42",
28    "int4val" => "42",
29    "int8val" => "42",
30    "stringval" => "The Answer",
31    "boolval" => true,
32    "dateval" => '2015-12-14',
33    "textval" => "some text",
34    "tsval"   => 19990108,
35    "byteaval" => 0,
36);
37$statement->execute($vals);
38
39$select = $db->query('SELECT int2col, int4col, int8col, stringcol, boolcol, datecol, textcol, tscol, byteacol FROM bugtest_62498');
40$meta = [];
41for ($i=0; $i < count($vals); $i++) {
42  $meta[] = $select->getColumnMeta($i);
43}
44var_dump($meta);
45
46?>
47Done
48--EXPECTF--
49Begin test...
50array(9) {
51  [0]=>
52  array(8) {
53    ["pgsql:oid"]=>
54    int(21)
55    ["pgsql:table_oid"]=>
56    int(%d)
57    ["table"]=>
58    string(13) "bugtest_62498"
59    ["native_type"]=>
60    string(4) "int2"
61    ["pdo_type"]=>
62    int(1)
63    ["name"]=>
64    string(7) "int2col"
65    ["len"]=>
66    int(2)
67    ["precision"]=>
68    int(-1)
69  }
70  [1]=>
71  array(8) {
72    ["pgsql:oid"]=>
73    int(23)
74    ["pgsql:table_oid"]=>
75    int(%d)
76    ["table"]=>
77    string(13) "bugtest_62498"
78    ["native_type"]=>
79    string(4) "int4"
80    ["pdo_type"]=>
81    int(1)
82    ["name"]=>
83    string(7) "int4col"
84    ["len"]=>
85    int(4)
86    ["precision"]=>
87    int(-1)
88  }
89  [2]=>
90  array(8) {
91    ["pgsql:oid"]=>
92    int(20)
93    ["pgsql:table_oid"]=>
94    int(%d)
95    ["table"]=>
96    string(13) "bugtest_62498"
97    ["native_type"]=>
98    string(4) "int8"
99    ["pdo_type"]=>
100    int(1)
101    ["name"]=>
102    string(7) "int8col"
103    ["len"]=>
104    int(8)
105    ["precision"]=>
106    int(-1)
107  }
108  [3]=>
109  array(8) {
110    ["pgsql:oid"]=>
111    int(1043)
112    ["pgsql:table_oid"]=>
113    int(%d)
114    ["table"]=>
115    string(13) "bugtest_62498"
116    ["native_type"]=>
117    string(7) "varchar"
118    ["pdo_type"]=>
119    int(2)
120    ["name"]=>
121    string(9) "stringcol"
122    ["len"]=>
123    int(-1)
124    ["precision"]=>
125    int(259)
126  }
127  [4]=>
128  array(8) {
129    ["pgsql:oid"]=>
130    int(16)
131    ["pgsql:table_oid"]=>
132    int(%d)
133    ["table"]=>
134    string(13) "bugtest_62498"
135    ["native_type"]=>
136    string(4) "bool"
137    ["pdo_type"]=>
138    int(5)
139    ["name"]=>
140    string(7) "boolcol"
141    ["len"]=>
142    int(1)
143    ["precision"]=>
144    int(-1)
145  }
146  [5]=>
147  array(8) {
148    ["pgsql:oid"]=>
149    int(1082)
150    ["pgsql:table_oid"]=>
151    int(%d)
152    ["table"]=>
153    string(13) "bugtest_62498"
154    ["native_type"]=>
155    string(4) "date"
156    ["pdo_type"]=>
157    int(2)
158    ["name"]=>
159    string(7) "datecol"
160    ["len"]=>
161    int(4)
162    ["precision"]=>
163    int(-1)
164  }
165  [6]=>
166  array(8) {
167    ["pgsql:oid"]=>
168    int(25)
169    ["pgsql:table_oid"]=>
170    int(%d)
171    ["table"]=>
172    string(13) "bugtest_62498"
173    ["native_type"]=>
174    string(4) "text"
175    ["pdo_type"]=>
176    int(2)
177    ["name"]=>
178    string(7) "textcol"
179    ["len"]=>
180    int(-1)
181    ["precision"]=>
182    int(-1)
183  }
184  [7]=>
185  array(8) {
186    ["pgsql:oid"]=>
187    int(1114)
188    ["pgsql:table_oid"]=>
189    int(%d)
190    ["table"]=>
191    string(13) "bugtest_62498"
192    ["native_type"]=>
193    string(9) "timestamp"
194    ["pdo_type"]=>
195    int(2)
196    ["name"]=>
197    string(5) "tscol"
198    ["len"]=>
199    int(8)
200    ["precision"]=>
201    int(-1)
202  }
203  [8]=>
204  array(8) {
205    ["pgsql:oid"]=>
206    int(17)
207    ["pgsql:table_oid"]=>
208    int(%d)
209    ["table"]=>
210    string(13) "bugtest_62498"
211    ["native_type"]=>
212    string(5) "bytea"
213    ["pdo_type"]=>
214    int(3)
215    ["name"]=>
216    string(8) "byteacol"
217    ["len"]=>
218    int(-1)
219    ["precision"]=>
220    int(-1)
221  }
222}
223Done
224