felipe                                   Fri, 10 Dec 2010 00:33:48 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=306149

Log:
- Fixed bug #39199 (Cannot load Lob data with more than 4000 bytes on ORACLE 10)
  patch by: spatar at mail dot nnov dot ru

Bug: http://bugs.php.net/39199 (Open) Cannot load Lob data with more than 4000 
bytes on ORACLE 10
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/pdo_oci/oci_statement.c
    A   php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_fread_1.phpt
    A   php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_stream_1.phpt
    U   php/php-src/trunk/ext/pdo_oci/oci_statement.c
    A   php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_fread_1.phpt
    A   php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_stream_1.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2010-12-10 00:30:23 UTC (rev 306148)
+++ php/php-src/branches/PHP_5_3/NEWS	2010-12-10 00:33:48 UTC (rev 306149)
@@ -1,6 +1,9 @@
 ´╗┐PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 20??, PHP 5.3.5
+- PDO Oracle driver:
+  . Fixed bug #39199 (Cannot load Lob data with more than 4000 bytes on
+    ORACLE 10). (spatar at mail dot nnov dot ru)

 09 Dec 2010, PHP 5.3.4
 - Upgraded bundled Sqlite3 to version 3.7.3. (Ilia)

Modified: php/php-src/branches/PHP_5_3/ext/pdo_oci/oci_statement.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_oci/oci_statement.c	2010-12-10 00:30:23 UTC (rev 306148)
+++ php/php-src/branches/PHP_5_3/ext/pdo_oci/oci_statement.c	2010-12-10 00:33:48 UTC (rev 306149)
@@ -31,6 +31,8 @@
 #include "php_pdo_oci_int.h"
 #include "Zend/zend_extensions.h"

+#define PDO_OCI_LOBMAXSIZE (4294967295UL) /* OCI_LOBMAXSIZE */
+
 #define STMT_CALL(name, params)											\
 	do {																\
 		S->last_err = name params;										\
@@ -634,11 +636,14 @@
 		&amt, self->offset, buf, count,
 		NULL, NULL, 0, SQLCS_IMPLICIT);

-	if (r != OCI_SUCCESS) {
+	if (r != OCI_SUCCESS && r != OCI_NEED_DATA) {
 		return (size_t)-1;
 	}

 	self->offset += amt;
+	if (amt < count) {
+		stream->eof = 1;
+	}
 	return amt;
 }

@@ -664,14 +669,17 @@
 	return 0;
 }

-/* TODO: implement
 static int oci_blob_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC)
 {
 	struct oci_lob_self *self = (struct oci_lob_self*)stream->abstract;

-	return -1;
+	if (offset >= PDO_OCI_LOBMAXSIZE) {
+		return -1;
+	} else {
+		self->offset = offset + 1;  /* Oracle LOBS are 1-based, but PHP is 0-based */
+		return 0;
+	}
 }
-*/

 static php_stream_ops oci_blob_stream_ops = {
 	oci_blob_write,
@@ -679,7 +687,7 @@
 	oci_blob_close,
 	oci_blob_flush,
 	"pdo_oci blob stream",
-	NULL, /*oci_blob_seek,*/
+	oci_blob_seek,
 	NULL,
 	NULL,
 	NULL

Added: php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_fread_1.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_fread_1.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_fread_1.phpt	2010-12-10 00:33:48 UTC (rev 306149)
@@ -0,0 +1,59 @@
+--TEST--
+PDO_OCI: check fread() EOF
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
+require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
+
+$dbh = PDOTest::factory();
+
+$dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+// Initialization
+$stmtarray = array(
+    "begin execute immediate 'drop table pdo_oci_fread_tab'; exception when others then null; end;",
+	"create table pdo_oci_fread_tab (id number, data clob)",
+    "declare
+    lob1 clob := 'abc' || lpad('j',4020,'j') || 'xyz';
+   begin
+    insert into pdo_oci_fread_tab (id,data) values (1, lob1);
+  end;"
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+echo "Test 1\n";
+
+$s = $dbh->query("select data from pdo_oci_fread_tab where id = 1");
+$r = $s->fetch();
+$sh = $r['data'];
+
+while (!feof($sh)) {
+    $buffer = fread($sh,1024);
+    echo '*'.$buffer.'*';
+}
+echo "\n";
+fclose($sh);
+
+// Clean up
+
+$stmtarray = array(
+	"drop table pdo_oci_fread_tab"
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+?>
+--EXPECTF--
+Test 1
+*abcjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj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jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjxyz*


Property changes on: php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_fread_1.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_stream_1.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_stream_1.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_stream_1.phpt	2010-12-10 00:33:48 UTC (rev 306149)
@@ -0,0 +1,112 @@
+--TEST--
+PDO_OCI: stream_get_contents length & offset test
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
+require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
+
+$dbh = PDOTest::factory();
+
+$dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+// Initialization
+...@$dbh->exec("drop table pdo_oci_stream_1_tab");
+
+$stmtarray = array(
+	"create table pdo_oci_stream_1_tab (id number, data clob)",
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+$dbh->exec("
+  declare
+    lob1 clob := 'abc' || lpad('j',30000,'j') || 'xyz';
+   begin
+    insert into pdo_oci_stream_1_tab (id,data) values (1, 'abcdefghijklmnopqrstuvwxyz');
+    insert into pdo_oci_stream_1_tab (id,data) values (2, lob1);
+  end;");
+
+echo "Test 1\n";
+
+$s = $dbh->prepare("select data from pdo_oci_stream_1_tab where id = 1");
+$s->execute();
+$r = $s->fetch();
+
+// stream_get_contents ( resource $handle [, int $maxlength = -1 [, int $offset = -1 ]] )
+echo 'Read '.stream_get_contents($r['data'], 1, 1)."$\n";  // b
+echo 'Read '.stream_get_contents($r['data'], 2, 1)."$\n";  // cd
+echo 'Read '.stream_get_contents($r['data'], 2, 0)."$\n";  // ab
+echo 'Read '.stream_get_contents($r['data'], 26, 0)."$\n"; // abcdefghijklmnopqrstuvwxyz
+echo 'Read '.stream_get_contents($r['data'], 27, 0)."$\n"; // abcdefghijklmnopqrstuvwxyz
+echo 'Read '.stream_get_contents($r['data'], 27, 1)."$\n"; // bcdefghijklmnopqrstuvwxyz
+echo 'Read '.stream_get_contents($r['data'], 1, 20)."$\n"; // u
+echo 'Read '.stream_get_contents($r['data'], 1, 25)."$\n"; // z
+echo 'Read '.stream_get_contents($r['data'], 1, 26)."$\n"; // <blank>
+echo 'Read '.stream_get_contents($r['data'], 1, 0)."$\n";  // a
+
+echo "\nTest 2\n";
+
+$s = $dbh->prepare("select data from pdo_oci_stream_1_tab where id = 2");
+$s->execute();
+$r = $s->fetch();
+
+echo 'Read '.stream_get_contents($r['data'], 5, 0)."\n";           // abcjj
+echo 'Read '.stream_get_contents($r['data'], 5, 2)."\n";           // cjjjj
+echo 'Read '.stream_get_contents($r['data'], 6, 1)."\n";           // bcjjjj
+echo 'Read '.strlen(stream_get_contents($r['data'], -1,0))."\n";   // 30006
+echo 'Read '.strlen(stream_get_contents($r['data'], 0,0))."\n";    // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], 0,1))."\n";    // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], 10,100))."\n"; // 10
+echo 'Read '.stream_get_contents($r['data'], 6, 30000)."\n";       // jjjxyz
+echo 'Read '.stream_get_contents($r['data'], 7, 30000)."\n";       // jjjxyz
+echo 'Read '.strlen(stream_get_contents($r['data']))."\n";         // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], 0))."\n";      // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], -1))."\n";     // 0
+echo 'Read '.stream_get_contents($r['data'], -1, 30000)."\n";      // jjjxyz
+
+// Clean up
+
+$stmtarray = array(
+	"drop table pdo_oci_stream_1_tab"
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+?>
+--EXPECTF--
+Test 1
+Read b$
+Read cd$
+Read ab$
+Read abcdefghijklmnopqrstuvwxyz$
+Read abcdefghijklmnopqrstuvwxyz$
+Read bcdefghijklmnopqrstuvwxyz$
+Read u$
+Read z$
+Read $
+Read a$
+
+Test 2
+Read abcjj
+Read cjjjj
+Read bcjjjj
+Read 30006
+Read 0
+Read 0
+Read 10
+Read jjjxyz
+Read jjjxyz
+Read 0
+Read 0
+Read 0
+Read jjjxyz
\ No newline at end of file


Property changes on: php/php-src/branches/PHP_5_3/ext/pdo_oci/tests/pdo_oci_stream_1.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/ext/pdo_oci/oci_statement.c
===================================================================
--- php/php-src/trunk/ext/pdo_oci/oci_statement.c	2010-12-10 00:30:23 UTC (rev 306148)
+++ php/php-src/trunk/ext/pdo_oci/oci_statement.c	2010-12-10 00:33:48 UTC (rev 306149)
@@ -31,6 +31,8 @@
 #include "php_pdo_oci_int.h"
 #include "Zend/zend_extensions.h"

+#define PDO_OCI_LOBMAXSIZE (4294967295UL) /* OCI_LOBMAXSIZE */
+
 #define STMT_CALL(name, params)											\
 	do {																\
 		S->last_err = name params;										\
@@ -634,11 +636,14 @@
 		&amt, self->offset, buf, count,
 		NULL, NULL, 0, SQLCS_IMPLICIT);

-	if (r != OCI_SUCCESS) {
+	if (r != OCI_SUCCESS && r != OCI_NEED_DATA) {
 		return (size_t)-1;
 	}

 	self->offset += amt;
+	if (amt < count) {
+		stream->eof = 1;
+	}
 	return amt;
 }

@@ -664,14 +669,17 @@
 	return 0;
 }

-/* TODO: implement
 static int oci_blob_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC)
 {
 	struct oci_lob_self *self = (struct oci_lob_self*)stream->abstract;

-	return -1;
+	if (offset >= PDO_OCI_LOBMAXSIZE) {
+		return -1;
+	} else {
+		self->offset = offset + 1;  /* Oracle LOBS are 1-based, but PHP is 0-based */
+		return 0;
+	}
 }
-*/

 static php_stream_ops oci_blob_stream_ops = {
 	oci_blob_write,
@@ -679,7 +687,7 @@
 	oci_blob_close,
 	oci_blob_flush,
 	"pdo_oci blob stream",
-	NULL, /*oci_blob_seek,*/
+	oci_blob_seek,
 	NULL,
 	NULL,
 	NULL

Added: php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_fread_1.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_fread_1.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_fread_1.phpt	2010-12-10 00:33:48 UTC (rev 306149)
@@ -0,0 +1,59 @@
+--TEST--
+PDO_OCI: check fread() EOF
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
+require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
+
+$dbh = PDOTest::factory();
+
+$dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+// Initialization
+$stmtarray = array(
+    "begin execute immediate 'drop table pdo_oci_fread_tab'; exception when others then null; end;",
+	"create table pdo_oci_fread_tab (id number, data clob)",
+    "declare
+    lob1 clob := 'abc' || lpad('j',4020,'j') || 'xyz';
+   begin
+    insert into pdo_oci_fread_tab (id,data) values (1, lob1);
+  end;"
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+echo "Test 1\n";
+
+$s = $dbh->query("select data from pdo_oci_fread_tab where id = 1");
+$r = $s->fetch();
+$sh = $r['data'];
+
+while (!feof($sh)) {
+    $buffer = fread($sh,1024);
+    echo '*'.$buffer.'*';
+}
+echo "\n";
+fclose($sh);
+
+// Clean up
+
+$stmtarray = array(
+	"drop table pdo_oci_fread_tab"
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+?>
+--EXPECTF--
+Test 1
+*abcjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj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jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjxyz*


Property changes on: php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_fread_1.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_stream_1.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_stream_1.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_stream_1.phpt	2010-12-10 00:33:48 UTC (rev 306149)
@@ -0,0 +1,112 @@
+--TEST--
+PDO_OCI: stream_get_contents length & offset test
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
+require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
+
+$dbh = PDOTest::factory();
+
+$dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+// Initialization
+...@$dbh->exec("drop table pdo_oci_stream_1_tab");
+
+$stmtarray = array(
+	"create table pdo_oci_stream_1_tab (id number, data clob)",
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+$dbh->exec("
+  declare
+    lob1 clob := 'abc' || lpad('j',30000,'j') || 'xyz';
+   begin
+    insert into pdo_oci_stream_1_tab (id,data) values (1, 'abcdefghijklmnopqrstuvwxyz');
+    insert into pdo_oci_stream_1_tab (id,data) values (2, lob1);
+  end;");
+
+echo "Test 1\n";
+
+$s = $dbh->prepare("select data from pdo_oci_stream_1_tab where id = 1");
+$s->execute();
+$r = $s->fetch();
+
+// stream_get_contents ( resource $handle [, int $maxlength = -1 [, int $offset = -1 ]] )
+echo 'Read '.stream_get_contents($r['data'], 1, 1)."$\n";  // b
+echo 'Read '.stream_get_contents($r['data'], 2, 1)."$\n";  // cd
+echo 'Read '.stream_get_contents($r['data'], 2, 0)."$\n";  // ab
+echo 'Read '.stream_get_contents($r['data'], 26, 0)."$\n"; // abcdefghijklmnopqrstuvwxyz
+echo 'Read '.stream_get_contents($r['data'], 27, 0)."$\n"; // abcdefghijklmnopqrstuvwxyz
+echo 'Read '.stream_get_contents($r['data'], 27, 1)."$\n"; // bcdefghijklmnopqrstuvwxyz
+echo 'Read '.stream_get_contents($r['data'], 1, 20)."$\n"; // u
+echo 'Read '.stream_get_contents($r['data'], 1, 25)."$\n"; // z
+echo 'Read '.stream_get_contents($r['data'], 1, 26)."$\n"; // <blank>
+echo 'Read '.stream_get_contents($r['data'], 1, 0)."$\n";  // a
+
+echo "\nTest 2\n";
+
+$s = $dbh->prepare("select data from pdo_oci_stream_1_tab where id = 2");
+$s->execute();
+$r = $s->fetch();
+
+echo 'Read '.stream_get_contents($r['data'], 5, 0)."\n";           // abcjj
+echo 'Read '.stream_get_contents($r['data'], 5, 2)."\n";           // cjjjj
+echo 'Read '.stream_get_contents($r['data'], 6, 1)."\n";           // bcjjjj
+echo 'Read '.strlen(stream_get_contents($r['data'], -1,0))."\n";   // 30006
+echo 'Read '.strlen(stream_get_contents($r['data'], 0,0))."\n";    // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], 0,1))."\n";    // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], 10,100))."\n"; // 10
+echo 'Read '.stream_get_contents($r['data'], 6, 30000)."\n";       // jjjxyz
+echo 'Read '.stream_get_contents($r['data'], 7, 30000)."\n";       // jjjxyz
+echo 'Read '.strlen(stream_get_contents($r['data']))."\n";         // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], 0))."\n";      // 0
+echo 'Read '.strlen(stream_get_contents($r['data'], -1))."\n";     // 0
+echo 'Read '.stream_get_contents($r['data'], -1, 30000)."\n";      // jjjxyz
+
+// Clean up
+
+$stmtarray = array(
+	"drop table pdo_oci_stream_1_tab"
+);
+
+foreach ($stmtarray as $stmt) {
+	$dbh->exec($stmt);
+}
+
+?>
+--EXPECTF--
+Test 1
+Read b$
+Read cd$
+Read ab$
+Read abcdefghijklmnopqrstuvwxyz$
+Read abcdefghijklmnopqrstuvwxyz$
+Read bcdefghijklmnopqrstuvwxyz$
+Read u$
+Read z$
+Read $
+Read a$
+
+Test 2
+Read abcjj
+Read cjjjj
+Read bcjjjj
+Read 30006
+Read 0
+Read 0
+Read 10
+Read jjjxyz
+Read jjjxyz
+Read 0
+Read 0
+Read 0
+Read jjjxyz
\ No newline at end of file


Property changes on: php/php-src/trunk/ext/pdo_oci/tests/pdo_oci_stream_1.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to