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