xref: /php-src/ext/pdo_pgsql/tests/bug46274.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, true);
17
18try {
19    @$db->query("SET bytea_output = 'escape'");
20} catch (Exception $e) {
21}
22
23$db->query('CREATE TABLE test_one_blob_46274_1 (id SERIAL NOT NULL, blob1 BYTEA)');
24
25$stmt = $db->prepare("INSERT INTO test_one_blob_46274_1 (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_1");
52// Resource
53var_dump($res->fetch());
54
55// Empty string
56var_dump($res->fetch());
57
58// Empty string
59var_dump($res->fetch());
60
61// NULL
62var_dump($res->fetch());
63?>
64--CLEAN--
65<?php
66require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
67$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
68$db->query('DROP TABLE IF EXISTS test_one_blob_46274_1');
69?>
70--EXPECT--
71array(2) {
72  ["blob1"]=>
73  string(3) "foo"
74  [0]=>
75  string(3) "foo"
76}
77array(2) {
78  ["blob1"]=>
79  string(0) ""
80  [0]=>
81  string(0) ""
82}
83array(2) {
84  ["blob1"]=>
85  string(0) ""
86  [0]=>
87  string(0) ""
88}
89array(2) {
90  ["blob1"]=>
91  NULL
92  [0]=>
93  NULL
94}
95