1--TEST--
2PDO_OCI: stream_get_contents length & offset test
3--EXTENSIONS--
4pdo
5pdo_oci
6--SKIPIF--
7<?php
8require(__DIR__.'/../../pdo/tests/pdo_test.inc');
9if (!strpos(strtolower(getenv('PDOTEST_DSN')), 'charset=we8mswin1252')) die('skip expected output valid for WE8MSWIN1252 character set');
10PDOTest::skip();
11?>
12--FILE--
13<?php
14
15require(__DIR__ . '/../../pdo/tests/pdo_test.inc');
16
17$dbh = PDOTest::factory();
18
19$dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
20
21// Initialization
22@$dbh->exec("drop table pdo_oci_stream_1_tab");
23
24$stmtarray = array(
25    "create table pdo_oci_stream_1_tab (id number, data clob)",
26);
27
28foreach ($stmtarray as $stmt) {
29    $dbh->exec($stmt);
30}
31
32$dbh->exec("
33  declare
34    lob1 clob := 'abc' || lpad('j',30000,'j') || 'xyz';
35   begin
36    insert into pdo_oci_stream_1_tab (id,data) values (1, 'abcdefghijklmnopqrstuvwxyz');
37    insert into pdo_oci_stream_1_tab (id,data) values (2, lob1);
38  end;");
39
40echo "Test 1\n";
41
42$s = $dbh->prepare("select data from pdo_oci_stream_1_tab where id = 1");
43$s->execute();
44$r = $s->fetch();
45
46// stream_get_contents ( resource $handle [, int $maxlength = -1 [, int $offset = -1 ]] )
47echo 'Read '.stream_get_contents($r['data'], 1, 1)."$\n";  // b
48echo 'Read '.stream_get_contents($r['data'], 2, 1)."$\n";  // cd
49echo 'Read '.stream_get_contents($r['data'], 2, 0)."$\n";  // ab
50echo 'Read '.stream_get_contents($r['data'], 26, 0)."$\n"; // abcdefghijklmnopqrstuvwxyz
51echo 'Read '.stream_get_contents($r['data'], 27, 0)."$\n"; // abcdefghijklmnopqrstuvwxyz
52echo 'Read '.stream_get_contents($r['data'], 27, 1)."$\n"; // bcdefghijklmnopqrstuvwxyz
53echo 'Read '.stream_get_contents($r['data'], 1, 20)."$\n"; // u
54echo 'Read '.stream_get_contents($r['data'], 1, 25)."$\n"; // z
55echo 'Read '.stream_get_contents($r['data'], 1, 26)."$\n"; // <blank>
56echo 'Read '.stream_get_contents($r['data'], 1, 0)."$\n";  // a
57
58echo "\nTest 2\n";
59
60$s = $dbh->prepare("select data from pdo_oci_stream_1_tab where id = 2");
61$s->execute();
62$r = $s->fetch();
63
64echo 'Read '.stream_get_contents($r['data'], 5, 0)."\n";           // abcjj
65echo 'Read '.stream_get_contents($r['data'], 5, 2)."\n";           // cjjjj
66echo 'Read '.stream_get_contents($r['data'], 6, 1)."\n";           // bcjjjj
67echo 'Read '.strlen(stream_get_contents($r['data'], -1,0))."\n";   // 30006
68echo 'Read '.strlen(stream_get_contents($r['data'], 0,0))."\n";    // 0
69echo 'Read '.strlen(stream_get_contents($r['data'], 0,1))."\n";    // 0
70echo 'Read '.strlen(stream_get_contents($r['data'], 10,100))."\n"; // 10
71echo 'Read '.stream_get_contents($r['data'], 6, 30000)."\n";       // jjjxyz
72echo 'Read '.stream_get_contents($r['data'], 7, 30000)."\n";       // jjjxyz
73echo 'Read '.strlen(stream_get_contents($r['data']))."\n";         // 0
74echo 'Read '.strlen(stream_get_contents($r['data'], 0))."\n";      // 0
75echo 'Read '.strlen(stream_get_contents($r['data'], -1))."\n";     // 0
76echo 'Read '.stream_get_contents($r['data'], -1, 30000)."\n";      // jjjxyz
77
78// Clean up
79
80$stmtarray = array(
81    "drop table pdo_oci_stream_1_tab"
82);
83
84foreach ($stmtarray as $stmt) {
85    $dbh->exec($stmt);
86}
87
88?>
89--EXPECT--
90Test 1
91Read b$
92Read cd$
93Read ab$
94Read abcdefghijklmnopqrstuvwxyz$
95Read abcdefghijklmnopqrstuvwxyz$
96Read bcdefghijklmnopqrstuvwxyz$
97Read u$
98Read z$
99Read $
100Read a$
101
102Test 2
103Read abcjj
104Read cjjjj
105Read bcjjjj
106Read 30006
107Read 0
108Read 0
109Read 10
110Read jjjxyz
111Read jjjxyz
112Read 0
113Read 0
114Read 0
115Read jjjxyz
116