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