diff options
Diffstat (limited to 'ext/pdo_oci')
-rwxr-xr-x | ext/pdo_oci/oci_statement.c | 18 | ||||
-rw-r--r-- | ext/pdo_oci/tests/pdo_oci_fread_1.phpt | 59 | ||||
-rw-r--r-- | ext/pdo_oci/tests/pdo_oci_stream_1.phpt | 112 |
3 files changed, 184 insertions, 5 deletions
diff --git a/ext/pdo_oci/oci_statement.c b/ext/pdo_oci/oci_statement.c index 8b0452a957..df07327949 100755 --- a/ext/pdo_oci/oci_statement.c +++ b/ext/pdo_oci/oci_statement.c @@ -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 @@ static size_t oci_blob_read(php_stream *stream, char *buf, size_t count TSRMLS_D &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 @@ static int oci_blob_flush(php_stream *stream TSRMLS_DC) 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 @@ static php_stream_ops oci_blob_stream_ops = { oci_blob_close, oci_blob_flush, "pdo_oci blob stream", - NULL, /*oci_blob_seek,*/ + oci_blob_seek, NULL, NULL, NULL diff --git a/ext/pdo_oci/tests/pdo_oci_fread_1.phpt b/ext/pdo_oci/tests/pdo_oci_fread_1.phpt new file mode 100644 index 0000000000..9604ef586d --- /dev/null +++ b/ext/pdo_oci/tests/pdo_oci_fread_1.phpt @@ -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 +*abcjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj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jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjxyz* diff --git a/ext/pdo_oci/tests/pdo_oci_stream_1.phpt b/ext/pdo_oci/tests/pdo_oci_stream_1.phpt new file mode 100644 index 0000000000..d054f88d4b --- /dev/null +++ b/ext/pdo_oci/tests/pdo_oci_stream_1.phpt @@ -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 |