thies           Sat Apr 14 01:38:46 2001 EDT

  Modified files:              
    /php4/ext/oci8      CREDITS oci8.c 
  Log:
  @- Added temporary LOB support in OCI8 (Patch by David Benson)
  
  
Index: php4/ext/oci8/CREDITS
diff -u php4/ext/oci8/CREDITS:1.2 php4/ext/oci8/CREDITS:1.3
--- php4/ext/oci8/CREDITS:1.2   Sat Apr 14 01:06:40 2001
+++ php4/ext/oci8/CREDITS       Sat Apr 14 01:38:46 2001
@@ -1,2 +1,2 @@
 OCI8
-Stig Bakken, Thies C. Arntzen, Andy Sautins
+Stig Bakken, Thies C. Arntzen, Andy Sautins, David Benson
Index: php4/ext/oci8/oci8.c
diff -u php4/ext/oci8/oci8.c:1.115 php4/ext/oci8/oci8.c:1.116
--- php4/ext/oci8/oci8.c:1.115  Fri Apr 13 07:43:39 2001
+++ php4/ext/oci8/oci8.c        Sat Apr 14 01:38:46 2001
@@ -16,10 +16,11 @@
    |          Thies C. Arntzen <[EMAIL PROTECTED]>                                     
           |
    |                                                                                  
                                                   |
    | Collection support by Andy Sautins <[EMAIL PROTECTED]>           |
+   | Temporary LOB support by David Benson <[EMAIL PROTECTED]>                 |
    +----------------------------------------------------------------------+
  */
 
-/* $Id: oci8.c,v 1.115 2001/04/13 14:43:39 thies Exp $ */
+/* $Id: oci8.c,v 1.116 2001/04/14 08:38:46 thies Exp $ */
 
 /* TODO list:
  *
@@ -51,10 +52,9 @@
 /* {{{ includes & stuff */
 
 #include "php.h"
-
-#include "ext/standard/head.h"
 #include "ext/standard/info.h"
 
+/* #define WITH_TEMP_LOBS 1 */
 #define WITH_COLLECTIONS 1
 
 #if HAVE_OCI8
@@ -209,6 +209,10 @@
 PHP_FUNCTION(ocistatementtype);
 PHP_FUNCTION(ocirowcount);
 PHP_FUNCTION(ocisetprefetch);
+#ifdef WITH_TEMP_LOBS
+PHP_FUNCTION(ociwritetemporarylob);
+PHP_FUNCTION(ocicloselob);
+#endif
 #ifdef WITH_COLLECTIONS
 PHP_FUNCTION(ocinewcollection);
 PHP_FUNCTION(ocifreecoll);
@@ -324,6 +328,10 @@
 static zend_function_entry php_oci_lob_class_functions[] = {
     PHP_FALIAS(load,       ociloadlob,       NULL)
     PHP_FALIAS(writetofile,    ociwritelobtofile,NULL)
+#ifdef WITH_TEMP_LOBS
+    PHP_FALIAS(writetemporary, ociwritetemporarylob,NULL)
+    PHP_FALIAS(close,          ocicloselob,      NULL)
+#endif
     PHP_FALIAS(save,       ocisavelob,       NULL)
     PHP_FALIAS(savefile,    ocisavelobfile,   NULL)
     PHP_FALIAS(free,       ocifreedesc,      NULL)
@@ -576,7 +584,7 @@
 
        php_info_print_table_start();
        php_info_print_table_row(2, "OCI8 Support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.115 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.116 $");
 #ifndef PHP_WIN32
        php_info_print_table_row(2, "Oracle Version", PHP_OCI8_VERSION );
        php_info_print_table_row(2, "Compile-time ORACLE_HOME", PHP_OCI8_DIR );
@@ -3174,6 +3182,151 @@
 }
 /* }}} */
 
+#ifdef WITH_TEMP_LOBS
+/* {{{ proto int ociwritetemporarylob(int stmt, int loc, string var)
+   Return the row count of an OCI statement */
+
+PHP_FUNCTION(ociwritetemporarylob)
+{
+    zval *id, **var;
+       OCILobLocator *mylob;
+       oci_connection *connection;
+       oci_descriptor *descr;
+       ub4 offset = 1;
+       ub4 loblen;
+
+    oci_debug ("oci_write_temporary_lob");
+
+       if ((id = getThis()) == 0) {
+        RETURN_FALSE;
+    }
+
+    if (_oci_get_ocidesc(id,&descr) == 0) {
+        RETURN_FALSE;
+    }
+
+    mylob = (OCILobLocator *) descr->ocidescr;
+
+    if (! mylob) {
+        RETURN_FALSE;
+    }
+
+    connection = descr->conn;
+
+    if (zend_get_parameters_ex(1, &var) == FAILURE) {
+        WRONG_PARAM_COUNT;
+    }
+
+    convert_to_string_ex(var);
+    
+    connection->error = 
+        OCILobCreateTemporary(connection->pServiceContext,
+                              connection->pError,
+                              mylob,
+                              OCI_DEFAULT,
+                              OCI_DEFAULT,
+                              OCI_TEMP_CLOB,
+                              TRUE,
+                              OCI_DURATION_SESSION);
+
+    if (connection->error) {
+        oci_error(connection->pError, "OCILobCreateTemporary", connection->error);
+        oci_handle_error(connection, connection->error);
+        RETURN_FALSE;
+    }
+
+    connection->error = 
+        OCILobOpen(connection->pServiceContext,
+                   connection->pError,
+                   mylob,
+                   OCI_LOB_READWRITE);
+
+    if (connection->error) {
+        oci_error(connection->pError, "OCILobOpen", connection->error);
+        oci_handle_error(connection, connection->error);
+        RETURN_FALSE;
+    }
+
+    convert_to_string_ex(var);
+    loblen = (*var)->value.str.len;
+       
+    if (loblen < 1) {
+        php_error(E_WARNING, "Cannot save a lob wich size is less than 1 byte");
+        RETURN_FALSE;
+    }
+
+    connection->error = 
+        OCILobWrite(connection->pServiceContext,
+                                       connection->pError,
+                                       mylob,
+                                       (ub4 *) &loblen,
+                                       (ub4) offset,
+                                       (dvoid *) (*var)->value.str.val,
+                                       (ub4) loblen,
+                                       OCI_ONE_PIECE,
+                                       (dvoid *)0,
+                    (sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,
+                                       (ub2) 0,
+                                       (ub1) SQLCS_IMPLICIT );
+
+    if (connection->error) {
+        oci_error(connection->pError, "OCILobWrite", connection->error);
+        oci_handle_error(connection, connection->error);
+        RETURN_FALSE;
+    }
+
+    RETURN_TRUE;
+}
+
+/* }}} */
+
+/* {{{ proto string ocicloselob(object lob)
+   Closes lob descriptor */
+
+PHP_FUNCTION(ocicloselob)
+{
+       zval *id;
+       int inx;
+       OCILobLocator *mylob;
+       oci_connection *connection;
+       oci_descriptor *descriptor;
+
+       if ((id = getThis()) != 0) {
+               inx = _oci_get_ocidesc(id,&descriptor);
+               if (inx) {
+
+            mylob = (OCILobLocator *) descriptor->ocidescr;
+
+            if (! mylob) {
+                RETURN_FALSE;
+            }
+
+            connection = descriptor->conn;
+
+            connection->error = OCILobClose (connection->pServiceContext, 
+                                             connection->pError, 
+                                             mylob);
+
+            if (connection->error) {
+                oci_error(connection->pError, "OCILobClose", connection->error);
+                oci_handle_error(connection, connection->error);
+                RETURN_FALSE;
+            }
+
+                       oci_debug("oci_close_lob: descr=%d",inx);
+                       RETURN_TRUE;
+               }
+       }
+
+       php_error(E_NOTICE, "OCICloselob() should not be called like this. Use 
+$somelob->close() to close a LOB");
+
+       RETURN_FALSE;
+}
+
+/* }}} */
+
+#endif 
+
 /* {{{ proto string ocinewdescriptor(int connection [, int type])
    Initialize a new empty descriptor LOB/FILE (LOB is default) */
 
@@ -3990,6 +4143,7 @@
 }
 
 /* }}} */
+
 
 /* {{{ proto string ociserverversion(int conn)
    Return a string containing server version information */



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to