bug60994.phpt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. --TEST--
  2. PDO OCI Bug #60994 (Reading a multibyte CLOB caps at 8192 characters)
  3. --CREDITS--
  4. Chuck Burgess
  5. ashnazg@php.net
  6. --EXTENSIONS--
  7. mbstring
  8. pdo
  9. pdo_oci
  10. --SKIPIF--
  11. <?php
  12. require __DIR__.'/../../pdo/tests/pdo_test.inc';
  13. if (!strpos(strtolower(getenv('PDOTEST_DSN')), 'charset=al32utf8')) die('skip expected output valid for AL32UTF8 character set');
  14. PDOTest::skip();
  15. ?>
  16. --FILE--
  17. <?php
  18. require 'ext/pdo/tests/pdo_test.inc';
  19. $dbh = PDOTest::factory();
  20. $dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
  21. $dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
  22. @$dbh->exec('DROP TABLE pdo_oci_bug60994');
  23. $dbh->exec('CREATE TABLE pdo_oci_bug60994 (id NUMBER, data CLOB)');
  24. $id = null;
  25. $insert = $dbh->prepare('INSERT INTO pdo_oci_bug60994 (id, data) VALUES (:id, :data)');
  26. $insert->bindParam(':id', $id, \PDO::PARAM_STR);
  27. $select = $dbh->prepare("SELECT data FROM pdo_oci_bug60994 WHERE id = :id");
  28. echo PHP_EOL, 'Test 1: j', PHP_EOL;
  29. $string1 = 'abc' . str_repeat('j', 8187) . 'xyz'; // 8193 chars total works fine here (even 1 million works fine, subject to memory_limit)
  30. $id = 1;
  31. $insert->bindParam(':data', $string1, \PDO::PARAM_STR, strlen($string1)); // length in bytes
  32. $insert->execute();
  33. $select->bindParam(':id', $id, \PDO::PARAM_STR);
  34. $select->execute();
  35. $row = $select->fetch();
  36. $stream1 = stream_get_contents($row['DATA']);
  37. $start1 = mb_substr($stream1, 0, 10);
  38. $ending1 = mb_substr($stream1, -10);
  39. echo 'size of string1 is ', strlen($string1), ' bytes, ', mb_strlen($string1), ' chars.', PHP_EOL;
  40. echo 'size of stream1 is ', strlen($stream1), ' bytes, ', mb_strlen($stream1), ' chars.', PHP_EOL;
  41. echo 'beg of stream1 is ', $start1, PHP_EOL;
  42. echo 'end of stream1 is ', $ending1, PHP_EOL;
  43. echo PHP_EOL, 'Test 2: £', PHP_EOL;
  44. $string2 = 'abc' . str_repeat('£', 8187) . 'xyz'; // 8193 chars total is when it breaks
  45. $id = 2;
  46. $insert->bindParam(':data', $string2, \PDO::PARAM_STR, strlen($string2)); // length in bytes
  47. $insert->execute();
  48. $select->bindParam(':id', $id, \PDO::PARAM_STR);
  49. $select->execute();
  50. $row = $select->fetch();
  51. $stream2 = stream_get_contents($row['DATA']);
  52. $start2 = mb_substr($stream2, 0, 10);
  53. $ending2 = mb_substr($stream2, -10);
  54. echo 'size of string2 is ', strlen($string2), ' bytes, ', mb_strlen($string2), ' chars.', PHP_EOL;
  55. echo 'size of stream2 is ', strlen($stream2), ' bytes, ', mb_strlen($stream2), ' chars.', PHP_EOL;
  56. echo 'beg of stream2 is ', $start2, PHP_EOL;
  57. echo 'end of stream2 is ', $ending2, PHP_EOL;
  58. echo PHP_EOL, 'Test 3: Җ', PHP_EOL;
  59. $string3 = 'abc' . str_repeat('Җ', 8187) . 'xyz'; // 8193 chars total is when it breaks
  60. $id = 3;
  61. $insert->bindParam(':data', $string3, \PDO::PARAM_STR, strlen($string3)); // length in bytes
  62. $insert->execute();
  63. $select->bindParam(':id', $id, \PDO::PARAM_STR);
  64. $select->execute();
  65. $row = $select->fetch();
  66. $stream3 = stream_get_contents($row['DATA']);
  67. $start3 = mb_substr($stream3, 0, 10);
  68. $ending3 = mb_substr($stream3, -10);
  69. echo 'size of string3 is ', strlen($string3), ' bytes, ', mb_strlen($string3), ' chars.', PHP_EOL;
  70. echo 'size of stream3 is ', strlen($stream3), ' bytes, ', mb_strlen($stream3), ' chars.', PHP_EOL;
  71. echo 'beg of stream3 is ', $start3, PHP_EOL;
  72. echo 'end of stream3 is ', $ending3, PHP_EOL;
  73. echo PHP_EOL, 'Test 4: の', PHP_EOL;
  74. $string4 = 'abc' . str_repeat('の', 8187) . 'xyz'; // 8193 chars total is when it breaks
  75. $id = 4;
  76. $insert->bindParam(':data', $string4, \PDO::PARAM_STR, strlen($string4)); // length in bytes
  77. $insert->execute();
  78. $select->bindParam(':id', $id, \PDO::PARAM_STR);
  79. $select->execute();
  80. $row = $select->fetch();
  81. $stream4 = stream_get_contents($row['DATA']);
  82. $start4 = mb_substr($stream4, 0, 10);
  83. $ending4 = mb_substr($stream4, -10);
  84. echo 'size of string4 is ', strlen($string4), ' bytes, ', mb_strlen($string4), ' chars.', PHP_EOL;
  85. echo 'size of stream4 is ', strlen($stream4), ' bytes, ', mb_strlen($stream4), ' chars.', PHP_EOL;
  86. echo 'beg of stream4 is ', $start4, PHP_EOL;
  87. echo 'end of stream4 is ', $ending4, PHP_EOL;
  88. ?>
  89. --XFAIL--
  90. Fails due to Bug 60994
  91. --EXPECT--
  92. Test 1: j
  93. size of string1 is 1000006 bytes, 1000006 chars.
  94. size of stream1 is 1000006 bytes, 1000006 chars.
  95. beg of stream1 is abcjjjjjjj
  96. end of stream1 is jjjjjjjxyz
  97. Test 2: £
  98. size of string2 is 16380 bytes, 8193 chars.
  99. size of stream2 is 16380 bytes, 8193 chars.
  100. beg of stream2 is abc£££££££
  101. end of stream2 is £££££££xyz
  102. Test 3: Җ
  103. size of string3 is 16380 bytes, 8193 chars.
  104. size of stream3 is 16380 bytes, 8193 chars.
  105. beg of stream3 is abcҖҖҖҖҖҖҖ
  106. end of stream3 is ҖҖҖҖҖҖҖxyz
  107. Test 4: の
  108. size of string4 is 24567 bytes, 8193 chars.
  109. size of stream4 is 24567 bytes, 8193 chars.
  110. beg of stream4 is abcののののののの
  111. end of stream4 is のののののののxyz