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