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