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