xref: /PHP-5.6/ext/pdo_oci/tests/bug46274_2.phpt (revision 43e4d8ca)
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_oci'))
6die('skip not loaded');
7require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require 'ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15
16$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
17
18try {
19	$db->exec("DROP TABLE test_one_blob");
20} catch (Exception $e) {
21}
22
23$db->beginTransaction();
24
25$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');
26
27$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, EMPTY_BLOB()) RETURNING blob1 INTO :foo");
28
29$data = 'foo';
30$blob = fopen('php://memory', 'a');
31fwrite($blob, $data);
32rewind($blob);
33
34$id = 1;
35$stmt->bindparam(':id', $id);
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$id = 1;
45$stmt->bindparam(':id', $id);
46$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
47$stmt->execute();
48
49$res = $db->query("SELECT blob1 from test_one_blob");
50// Resource
51var_dump($row = $res->fetch());
52var_dump(fread($row[0], 1024));
53fclose($row[0]);
54
55// Empty string
56var_dump($row = $res->fetch());
57var_dump(fread($row[0], 1024));
58fclose($row[0]);
59
60$db->exec("DROP TABLE test_one_blob");
61
62?>
63--XFAIL--
64Corrupts memory
65--EXPECTF--
66array(2) {
67  ["blob1"]=>
68  resource(%d) of type (stream)
69  [0]=>
70  resource(%d) of type (stream)
71}
72string(3) "foo"
73array(2) {
74  ["blob1"]=>
75  resource(%d) of type (stream)
76  [0]=>
77  resource(%d) of type (stream)
78}
79string(0) ""
80