xref: /PHP-7.1/ext/pdo_oci/tests/bug60994.phpt (revision 113213f0)
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
8/* $Id$ */
9if (!extension_loaded('mbstring') || !extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
10require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc';
11if (!strpos(strtolower(getenv('PDOTEST_DSN')), 'charset=al32utf8')) die('skip expected output valid for AL32UTF8 character set');
12PDOTest::skip();
13?>
14--FILE--
15<?php
16require '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
30echo 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);
41echo 'size of string1 is ', strlen($string1), ' bytes, ', mb_strlen($string1), ' chars.', PHP_EOL;
42echo 'size of stream1 is ', strlen($stream1), ' bytes, ', mb_strlen($stream1), ' chars.', PHP_EOL;
43echo 'beg  of stream1 is ', $start1, PHP_EOL;
44echo 'end  of stream1 is ', $ending1, PHP_EOL;
45
46
47echo 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);
58echo 'size of string2 is ', strlen($string2), ' bytes, ', mb_strlen($string2), ' chars.', PHP_EOL;
59echo 'size of stream2 is ', strlen($stream2), ' bytes, ', mb_strlen($stream2), ' chars.', PHP_EOL;
60echo 'beg  of stream2 is ', $start2, PHP_EOL;
61echo 'end  of stream2 is ', $ending2, PHP_EOL;
62
63
64echo 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);
75echo 'size of string3 is ', strlen($string3), ' bytes, ', mb_strlen($string3), ' chars.', PHP_EOL;
76echo 'size of stream3 is ', strlen($stream3), ' bytes, ', mb_strlen($stream3), ' chars.', PHP_EOL;
77echo 'beg  of stream3 is ', $start3, PHP_EOL;
78echo 'end  of stream3 is ', $ending3, PHP_EOL;
79
80
81echo 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);
92echo 'size of string4 is ', strlen($string4), ' bytes, ', mb_strlen($string4), ' chars.', PHP_EOL;
93echo 'size of stream4 is ', strlen($stream4), ' bytes, ', mb_strlen($stream4), ' chars.', PHP_EOL;
94echo 'beg  of stream4 is ', $start4, PHP_EOL;
95echo 'end  of stream4 is ', $ending4, PHP_EOL;
96--XFAIL--
97Fails due to Bug 60994
98--EXPECTF--
99Test 1:  j
100size of string1 is 1000006 bytes, 1000006 chars.
101size of stream1 is 1000006 bytes, 1000006 chars.
102beg  of stream1 is abcjjjjjjj
103end  of stream1 is jjjjjjjxyz
104
105Test 2:  £
106size of string2 is 16380 bytes, 8193 chars.
107size of stream2 is 16380 bytes, 8193 chars.
108beg  of stream2 is abc£££££££
109end  of stream2 is £££££££xyz
110
111Test 3:  Җ
112size of string3 is 16380 bytes, 8193 chars.
113size of stream3 is 16380 bytes, 8193 chars.
114beg  of stream3 is abcҖҖҖҖҖҖҖ
115end  of stream3 is ҖҖҖҖҖҖҖxyz
116
117Test 4:  の
118size of string4 is 24567 bytes, 8193 chars.
119size of stream4 is 24567 bytes, 8193 chars.
120beg  of stream4 is abcののののののの
121end  of stream4 is のののののののxyz
122