From 598aaba8ca50901a4846d41be5cd89619894c5a9 Mon Sep 17 00:00:00 2001
From: "Thies C. Arntzen" <thies@php.net>
Date: Tue, 14 Sep 1999 12:41:00 +0000
Subject: [PATCH] you can now position when doing lob-writes.

---
 ChangeLog       |  1 +
 ext/oci8/oci8.c | 59 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ddbf28d6f9..60953939cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG                                                    ChangeLog
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 ?? ?? 1999, Version 4.0 Beta 3
+- OCI8 supports appending and positioning when saving LOBs (Thies)
 - Added metaphone support (Thies)
 - OCI8 doesn't use define callbacks any longer. (Thies) 
 - OCI8 Driver now supports LOBs like PHP3. (Thies)
diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c
index 76be8491f5..a8bc112b68 100644
--- a/ext/oci8/oci8.c
+++ b/ext/oci8/oci8.c
@@ -2400,11 +2400,14 @@ PHP_FUNCTION(ocifreedesc)
 
 PHP_FUNCTION(ocisavelob)
 {
-	pval *id, **tmp, **conn, *arg;
+	pval *id, **tmp, **conn, *arg,*oarg;
 	OCILobLocator *mylob;
 	oci_connection *connection;
 	oci_descriptor *descr;
+	int offparam;
 	ub4 loblen;
+    ub4 curloblen;
+    ub4 offset;
 
 	if ((id = getThis()) != 0) {
    		if (zend_hash_find(id->value.obj.properties, "connection", sizeof("connection"), (void **)&conn) == FAILURE) {
@@ -2433,32 +2436,54 @@ PHP_FUNCTION(ocisavelob)
 			RETURN_FALSE;
 		}
 
-	    if (getParameters(ht, 1, &arg) == FAILURE) {
+		offset = 0;	
+	    if (getParameters(ht, 2, &arg, &oarg) == SUCCESS) {
+			convert_to_long(oarg);
+			offparam = oarg->value.lval;
+
+			connection->error =
+				OCILobGetLength(connection->pServiceContext,
+								connection->pError,
+								mylob,
+								&curloblen);
+
+			oci_debug("OCIsavedesc: curloblen=%d",curloblen);
+
+			if (offparam == -1) {
+				offset = curloblen;
+			} else if (offparam >= curloblen) {
+				php3_error(E_WARNING, "Offset smaller than current LOB-Size - appending");
+				offset = curloblen;
+			} else {
+				offset = offparam;
+			}
+    	} else if (getParameters(ht, 1, &arg) == FAILURE) {
         	WRONG_PARAM_COUNT;
     	}
 
+		offset++;
 		loblen = arg->value.str.len;
 	
 		if (loblen < 1) {
-			php_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
+			php3_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
 			RETURN_FALSE;
 		}
-		
+
 		connection->error = 
 			OCILobWrite(connection->pServiceContext,
-						connection->pError,
-						mylob,
-						&loblen,
-						(ub4) 1,
-						(dvoid *) arg->value.str.val,
-						(ub4) loblen,
-						OCI_ONE_PIECE,
-						(dvoid *)0,
-						(OCICallbackLobWrite) 0,
-						(ub2) 0,
-						(ub1) SQLCS_IMPLICIT );
-
-		oci_debug("OCIsavelob: size=%d",loblen);
+					connection->pError,
+					mylob,
+					&loblen,
+					(ub4) offset,
+					(dvoid *) arg->value.str.val,
+					(ub4) loblen,
+					OCI_ONE_PIECE,
+					(dvoid *)0,
+					(OCICallbackLobWrite) 0,
+					(ub2) 0,
+					(ub1) SQLCS_IMPLICIT );
+
+		oci_debug("OCIsavedesc: size=%d offset=%d",loblen,offset);
 
 		if (connection->error) {
 			oci_error(connection->pError, "OCILobWrite", connection->error);
-- 
2.40.0