xref: /php-src/ext/pdo_pgsql/tests/bug62498.phpt (revision f4a5db3e)
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 test62498 (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 test62498 (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 test62498');
40$meta = [];
41for ($i=0; $i < count($vals); $i++) {
42  $meta[] = $select->getColumnMeta($i);
43}
44var_dump($meta);
45
46?>
47Done
48--CLEAN--
49<?php
50require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
51$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
52$db->query('DROP TABLE IF EXISTS test62498');
53--EXPECTF--
54Begin test...
55array(9) {
56  [0]=>
57  array(8) {
58    ["pgsql:oid"]=>
59    int(21)
60    ["pgsql:table_oid"]=>
61    int(%d)
62    ["table"]=>
63    string(%s) "test62498"
64    ["native_type"]=>
65    string(4) "int2"
66    ["pdo_type"]=>
67    int(1)
68    ["name"]=>
69    string(7) "int2col"
70    ["len"]=>
71    int(2)
72    ["precision"]=>
73    int(-1)
74  }
75  [1]=>
76  array(8) {
77    ["pgsql:oid"]=>
78    int(23)
79    ["pgsql:table_oid"]=>
80    int(%d)
81    ["table"]=>
82    string(%s) "test62498"
83    ["native_type"]=>
84    string(4) "int4"
85    ["pdo_type"]=>
86    int(1)
87    ["name"]=>
88    string(7) "int4col"
89    ["len"]=>
90    int(4)
91    ["precision"]=>
92    int(-1)
93  }
94  [2]=>
95  array(8) {
96    ["pgsql:oid"]=>
97    int(20)
98    ["pgsql:table_oid"]=>
99    int(%d)
100    ["table"]=>
101    string(%s) "test62498"
102    ["native_type"]=>
103    string(4) "int8"
104    ["pdo_type"]=>
105    int(1)
106    ["name"]=>
107    string(7) "int8col"
108    ["len"]=>
109    int(8)
110    ["precision"]=>
111    int(-1)
112  }
113  [3]=>
114  array(8) {
115    ["pgsql:oid"]=>
116    int(1043)
117    ["pgsql:table_oid"]=>
118    int(%d)
119    ["table"]=>
120    string(%s) "test62498"
121    ["native_type"]=>
122    string(7) "varchar"
123    ["pdo_type"]=>
124    int(2)
125    ["name"]=>
126    string(9) "stringcol"
127    ["len"]=>
128    int(-1)
129    ["precision"]=>
130    int(259)
131  }
132  [4]=>
133  array(8) {
134    ["pgsql:oid"]=>
135    int(16)
136    ["pgsql:table_oid"]=>
137    int(%d)
138    ["table"]=>
139    string(%s) "test62498"
140    ["native_type"]=>
141    string(4) "bool"
142    ["pdo_type"]=>
143    int(5)
144    ["name"]=>
145    string(7) "boolcol"
146    ["len"]=>
147    int(1)
148    ["precision"]=>
149    int(-1)
150  }
151  [5]=>
152  array(8) {
153    ["pgsql:oid"]=>
154    int(1082)
155    ["pgsql:table_oid"]=>
156    int(%d)
157    ["table"]=>
158    string(%s) "test62498"
159    ["native_type"]=>
160    string(4) "date"
161    ["pdo_type"]=>
162    int(2)
163    ["name"]=>
164    string(7) "datecol"
165    ["len"]=>
166    int(4)
167    ["precision"]=>
168    int(-1)
169  }
170  [6]=>
171  array(8) {
172    ["pgsql:oid"]=>
173    int(25)
174    ["pgsql:table_oid"]=>
175    int(%d)
176    ["table"]=>
177    string(%s) "test62498"
178    ["native_type"]=>
179    string(4) "text"
180    ["pdo_type"]=>
181    int(2)
182    ["name"]=>
183    string(7) "textcol"
184    ["len"]=>
185    int(-1)
186    ["precision"]=>
187    int(-1)
188  }
189  [7]=>
190  array(8) {
191    ["pgsql:oid"]=>
192    int(1114)
193    ["pgsql:table_oid"]=>
194    int(%d)
195    ["table"]=>
196    string(%s) "test62498"
197    ["native_type"]=>
198    string(9) "timestamp"
199    ["pdo_type"]=>
200    int(2)
201    ["name"]=>
202    string(5) "tscol"
203    ["len"]=>
204    int(8)
205    ["precision"]=>
206    int(-1)
207  }
208  [8]=>
209  array(8) {
210    ["pgsql:oid"]=>
211    int(17)
212    ["pgsql:table_oid"]=>
213    int(%d)
214    ["table"]=>
215    string(%s) "test62498"
216    ["native_type"]=>
217    string(5) "bytea"
218    ["pdo_type"]=>
219    int(3)
220    ["name"]=>
221    string(8) "byteacol"
222    ["len"]=>
223    int(-1)
224    ["precision"]=>
225    int(-1)
226  }
227}
228Done
229