xref: /php-src/ext/pdo/tests/bug_34630.phpt (revision f4a5db3e)
1--TEST--
2PDO Common: Bug #34630 (inserting streams as LOBs)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17
18$driver = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
19$is_oci = $driver == 'oci';
20
21if ($is_oci) {
22    $db->exec('CREATE TABLE test34630 (id int NOT NULL PRIMARY KEY, val BLOB)');
23} else {
24    $db->exec('CREATE TABLE test34630 (id int NOT NULL PRIMARY KEY, val VARCHAR(256))');
25}
26$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
27
28$fp = tmpfile();
29fwrite($fp, "I am the LOB data");
30rewind($fp);
31
32if ($is_oci) {
33    /* oracle is a bit different; you need to initiate a transaction otherwise
34     * the empty blob will be committed implicitly when the statement is
35     * executed */
36    $db->beginTransaction();
37    $insert = $db->prepare("insert into test34630 (id, val) values (1, EMPTY_BLOB()) RETURNING val INTO :blob");
38} else {
39    $insert = $db->prepare("insert into test34630 (id, val) values (1, :blob)");
40}
41$insert->bindValue(':blob', $fp, PDO::PARAM_LOB);
42$insert->execute();
43$insert = null;
44
45$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
46var_dump($db->query("SELECT * from test34630")->fetchAll(PDO::FETCH_ASSOC));
47
48?>
49--CLEAN--
50<?php
51require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
52$db = PDOTest::factory();
53PDOTest::dropTableIfExists($db, "test34630");
54?>
55--EXPECT--
56array(1) {
57  [0]=>
58  array(2) {
59    ["id"]=>
60    string(1) "1"
61    ["val"]=>
62    string(17) "I am the LOB data"
63  }
64}
65