bug70700.phpt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. --TEST--
  2. Tests for LOBs with multibyte strings, reading them out in chunks
  3. (Doc Bug #70700)
  4. --CREDITS--
  5. Chuck Burgess
  6. ashnazg@php.net
  7. --EXTENSIONS--
  8. mbstring
  9. oci8
  10. --SKIPIF--
  11. <?php
  12. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  13. require(__DIR__.'/skipif.inc');
  14. ?>
  15. --ENV--
  16. NLS_LANG=.AL32UTF8
  17. --FILE--
  18. <?php
  19. require(__DIR__.'/connect.inc');
  20. $stmt = oci_parse($c, 'DROP TABLE oci8_bug70700');
  21. @oci_execute($stmt);
  22. oci_free_statement($stmt);
  23. $stmt = oci_parse($c, 'CREATE TABLE oci8_bug70700 (id NUMBER, data CLOB)');
  24. oci_execute($stmt);
  25. oci_free_statement($stmt);
  26. $id = null;
  27. $insert = oci_parse($c, 'INSERT INTO oci8_bug70700 (id, data) VALUES (:id, :data)');
  28. oci_bind_by_name($insert, ':id', $id);
  29. $select = oci_parse($c, "SELECT data FROM oci8_bug70700 WHERE id = :id");
  30. oci_bind_by_name($select, ':id', $id);
  31. echo PHP_EOL, 'Test 1: j', PHP_EOL;
  32. $string1 = 'abc' . str_repeat('j', 1000000) . 'xyz';
  33. $id = 1;
  34. $desc = oci_new_descriptor($c, OCI_D_LOB);
  35. oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB);
  36. $desc->writeTemporary($string1, OCI_TEMP_CLOB);
  37. oci_execute($insert);
  38. $desc->save($string1);
  39. oci_commit($c);
  40. $desc->close();
  41. oci_bind_by_name($select, ':id', $id);
  42. oci_execute($select);
  43. $row = oci_fetch_array($select, OCI_ASSOC);
  44. $lob = $row['DATA'];
  45. $fh = fopen('php://temp', 'rw');
  46. while (! $lob->eof()) {
  47. $data = $lob->read(8192); // read($characters), not read($bytes)
  48. fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes)
  49. }
  50. $lob->free();
  51. rewind($fh);
  52. $stream1a = stream_get_contents($fh);
  53. fclose($fh);
  54. $start1a = mb_substr($stream1a, 0, 10);
  55. $ending1a = mb_substr($stream1a, -10);
  56. echo 'size of string1 is ', strlen($string1), ' bytes, ', mb_strlen($string1), ' chars.', PHP_EOL;
  57. echo 'size of stream1a is ', strlen($stream1a), ' bytes, ', mb_strlen($stream1a), ' chars.', PHP_EOL;
  58. echo 'beg of stream1a is ', $start1a, PHP_EOL;
  59. echo 'end of stream1a is ', $ending1a, PHP_EOL;
  60. echo PHP_EOL, 'Test 2: £', PHP_EOL;
  61. $string2 = 'abc' . str_repeat('£', 4094) . 'xyz';
  62. $id = 2;
  63. $desc = oci_new_descriptor($c, OCI_D_LOB);
  64. oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB);
  65. $desc->writeTemporary($string2, OCI_TEMP_CLOB);
  66. oci_execute($insert);
  67. $desc->save($string2);
  68. oci_commit($c);
  69. $desc->close();
  70. oci_bind_by_name($select, ':id', $id);
  71. oci_execute($select);
  72. $row = oci_fetch_array($select, OCI_ASSOC);
  73. $lob = $row['DATA'];
  74. $fh = fopen('php://temp', 'rw');
  75. while (! $lob->eof()) {
  76. $data = $lob->read(8192); // read($characters), not read($bytes)
  77. fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes)
  78. }
  79. $lob->free();
  80. rewind($fh);
  81. $stream2a = stream_get_contents($fh);
  82. fclose($fh);
  83. $start2a = mb_substr($stream2a, 0, 10);
  84. $ending2a = mb_substr($stream2a, -10);
  85. echo 'size of string2 is ', strlen($string2), ' bytes, ', mb_strlen($string2), ' chars.', PHP_EOL;
  86. echo 'size of stream2a is ', strlen($stream2a), ' bytes, ', mb_strlen($stream2a), ' chars.', PHP_EOL;
  87. echo 'beg of stream2a is ', $start2a, PHP_EOL;
  88. echo 'end of stream2a is ', $ending2a, PHP_EOL;
  89. echo PHP_EOL, 'Test 3: Җ', PHP_EOL;
  90. $string3 = 'abc' . str_repeat('Җ', 4094) . 'xyz';
  91. $id = 3;
  92. $desc = oci_new_descriptor($c, OCI_D_LOB);
  93. oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB);
  94. $desc->writeTemporary($string3, OCI_TEMP_CLOB);
  95. oci_execute($insert);
  96. $desc->save($string3);
  97. oci_commit($c);
  98. $desc->close();
  99. oci_bind_by_name($select, ':id', $id);
  100. oci_execute($select);
  101. $row = oci_fetch_array($select, OCI_ASSOC);
  102. $lob = $row['DATA'];
  103. $fh = fopen('php://temp', 'rw');
  104. while (! $lob->eof()) {
  105. $data = $lob->read(8192); // read($characters), not read($bytes)
  106. fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes)
  107. }
  108. $lob->free();
  109. rewind($fh);
  110. $stream3a = stream_get_contents($fh);
  111. fclose($fh);
  112. $start3a = mb_substr($stream3a, 0, 10);
  113. $ending3a = mb_substr($stream3a, -10);
  114. echo 'size of string3 is ', strlen($string3), ' bytes, ', mb_strlen($string3), ' chars.', PHP_EOL;
  115. echo 'size of stream3a is ', strlen($stream3a), ' bytes, ', mb_strlen($stream3a), ' chars.', PHP_EOL;
  116. echo 'beg of stream3a is ', $start3a, PHP_EOL;
  117. echo 'end of stream3a is ', $ending3a, PHP_EOL;
  118. echo PHP_EOL, 'Test 4: の', PHP_EOL;
  119. $string4 = 'abc' . str_repeat('の', 2729) . 'xyz';
  120. $id = 4;
  121. $desc = oci_new_descriptor($c, OCI_D_LOB);
  122. oci_bind_by_name($insert, ':data', $desc, -1, OCI_B_CLOB);
  123. $desc->writeTemporary($string4, OCI_TEMP_CLOB);
  124. oci_execute($insert);
  125. $desc->save($string4);
  126. oci_commit($c);
  127. $desc->close();
  128. oci_bind_by_name($select, ':id', $id);
  129. oci_execute($select);
  130. $row = oci_fetch_array($select, OCI_ASSOC);
  131. $lob = $row['DATA'];
  132. $fh = fopen('php://temp', 'rw');
  133. while (! $lob->eof()) {
  134. $data = $lob->read(8192); // read($characters), not read($bytes)
  135. fwrite($fh, $data, strlen($data)); // fwrite(a, b, $bytes)
  136. }
  137. $lob->free();
  138. rewind($fh);
  139. $stream4a = stream_get_contents($fh);
  140. fclose($fh);
  141. $start4a = mb_substr($stream4a, 0, 10);
  142. $ending4a = mb_substr($stream4a, -10);
  143. echo 'size of string4 is ', strlen($string4), ' bytes, ', mb_strlen($string4), ' chars.', PHP_EOL;
  144. echo 'size of stream4a is ', strlen($stream4a), ' bytes, ', mb_strlen($stream4a), ' chars.', PHP_EOL;
  145. echo 'beg of stream4a is ', $start4a, PHP_EOL;
  146. echo 'end of stream4a is ', $ending4a, PHP_EOL;
  147. ?>
  148. --EXPECT--
  149. Test 1: j
  150. size of string1 is 1000006 bytes, 1000006 chars.
  151. size of stream1a is 1000006 bytes, 1000006 chars.
  152. beg of stream1a is abcjjjjjjj
  153. end of stream1a is jjjjjjjxyz
  154. Test 2: £
  155. size of string2 is 8194 bytes, 4100 chars.
  156. size of stream2a is 8194 bytes, 4100 chars.
  157. beg of stream2a is abc£££££££
  158. end of stream2a is £££££££xyz
  159. Test 3: Җ
  160. size of string3 is 8194 bytes, 4100 chars.
  161. size of stream3a is 8194 bytes, 4100 chars.
  162. beg of stream3a is abcҖҖҖҖҖҖҖ
  163. end of stream3a is ҖҖҖҖҖҖҖxyz
  164. Test 4: の
  165. size of string4 is 8193 bytes, 2735 chars.
  166. size of stream4a is 8193 bytes, 2735 chars.
  167. beg of stream4a is abcののののののの
  168. end of stream4a is のののののののxyz