xref: /php-src/ext/pdo_pgsql/tests/bug46274_2.phpt (revision 6fb81d23)
1--TEST--
2Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob)
3--EXTENSIONS--
4pdo_pgsql
5--SKIPIF--
6<?php
7require __DIR__ . '/config.inc';
8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
14$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
15
16$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
17
18try {
19        @$db->query("SET bytea_output = 'escape'");
20} catch (Exception $e) {
21}
22
23$db->query('CREATE TABLE test_one_blob_46274_2 (id SERIAL NOT NULL, blob1 BYTEA)');
24
25$stmt = $db->prepare("INSERT INTO test_one_blob_46274_2 (blob1) VALUES (:foo)");
26
27$data = 'foo';
28$blob = fopen('php://memory', 'a');
29fwrite($blob, $data);
30rewind($blob);
31
32$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
33$stmt->execute();
34
35$blob = '';
36$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
37$stmt->execute();
38
39$data = '';
40$blob = fopen('php://memory', 'a');
41fwrite($blob, $data);
42rewind($blob);
43
44$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
45$stmt->execute();
46
47$blob = NULL;
48$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
49$stmt->execute();
50
51$res = $db->query("SELECT blob1 from test_one_blob_46274_2");
52// Resource
53var_dump($x = $res->fetch());
54var_dump(fread($x['blob1'], 10));
55
56// Resource
57var_dump($res->fetch());
58var_dump(fread($x['blob1'], 10));
59
60// Resource
61var_dump($res->fetch());
62var_dump(fread($x['blob1'], 10));
63
64// NULL
65var_dump($res->fetch());
66?>
67--CLEAN--
68<?php
69require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
70$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
71$db->query('DROP TABLE IF EXISTS test_one_blob_46274_2');
72?>
73--EXPECTF--
74array(2) {
75  ["blob1"]=>
76  resource(%d) of type (stream)
77  [0]=>
78  resource(%d) of type (stream)
79}
80string(3) "foo"
81array(2) {
82  ["blob1"]=>
83  resource(%d) of type (stream)
84  [0]=>
85  resource(%d) of type (stream)
86}
87string(0) ""
88array(2) {
89  ["blob1"]=>
90  resource(%d) of type (stream)
91  [0]=>
92  resource(%d) of type (stream)
93}
94string(0) ""
95array(2) {
96  ["blob1"]=>
97  NULL
98  [0]=>
99  NULL
100}
101