bug_34630.phpt 1.5 KB

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