bug46274.phpt 1.6 KB

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