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