xref: /PHP-5.3/ext/pdo_pgsql/tests/bug46274.phpt (revision d2d4e044)
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 dirname(__FILE__) . '/config.inc';
7require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14
15$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
16
17$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
18
19$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");
20
21$data = 'foo';
22$blob = fopen('php://memory', 'a');
23fwrite($blob, $data);
24rewind($blob);
25
26$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
27$stmt->execute();
28
29$blob = '';
30$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
31$stmt->execute();
32
33$data = '';
34$blob = fopen('php://memory', 'a');
35fwrite($blob, $data);
36rewind($blob);
37
38$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
39$stmt->execute();
40
41$blob = NULL;
42$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
43$stmt->execute();
44
45$res = $db->query("SELECT blob1 from test_one_blob");
46// Resource
47var_dump($res->fetch());
48
49// Empty string
50var_dump($res->fetch());
51
52// Empty string
53var_dump($res->fetch());
54
55// NULL
56var_dump($res->fetch());
57
58$db->query('DROP TABLE test_one_blob');
59
60?>
61--EXPECTF--
62array(2) {
63  ["blob1"]=>
64  string(3) "foo"
65  [0]=>
66  string(3) "foo"
67}
68array(2) {
69  ["blob1"]=>
70  string(0) ""
71  [0]=>
72  string(0) ""
73}
74array(2) {
75  ["blob1"]=>
76  string(0) ""
77  [0]=>
78  string(0) ""
79}
80array(2) {
81  ["blob1"]=>
82  NULL
83  [0]=>
84  NULL
85}
86