bug46274_2.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, false);
  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($x = $res->fetch());
  44. var_dump(fread($x['blob1'], 10));
  45. // Resource
  46. var_dump($res->fetch());
  47. var_dump(fread($x['blob1'], 10));
  48. // Resource
  49. var_dump($res->fetch());
  50. var_dump(fread($x['blob1'], 10));
  51. // NULL
  52. var_dump($res->fetch());
  53. $db->query('DROP TABLE test_one_blob');
  54. ?>
  55. --EXPECTF--
  56. array(2) {
  57. ["blob1"]=>
  58. resource(%d) of type (stream)
  59. [0]=>
  60. resource(%d) of type (stream)
  61. }
  62. string(3) "foo"
  63. array(2) {
  64. ["blob1"]=>
  65. resource(%d) of type (stream)
  66. [0]=>
  67. resource(%d) of type (stream)
  68. }
  69. string(0) ""
  70. array(2) {
  71. ["blob1"]=>
  72. resource(%d) of type (stream)
  73. [0]=>
  74. resource(%d) of type (stream)
  75. }
  76. string(0) ""
  77. array(2) {
  78. ["blob1"]=>
  79. NULL
  80. [0]=>
  81. NULL
  82. }