]> granicus.if.org Git - php/commitdiff
add support for NCLOBs
authorAntony Dovgal <tony2001@php.net>
Wed, 9 Aug 2006 15:24:27 +0000 (15:24 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 9 Aug 2006 15:24:27 +0000 (15:24 +0000)
fix #35973 (Error ORA-24806 occurs when trying to fetch a NCLOB field)

ext/oci8/oci8_lob.c
ext/oci8/oci8_statement.c
ext/oci8/php_oci8_int.h
ext/oci8/tests/bug35973.phpt [new file with mode: 0644]

index 169489eadf35a60d917d6eb81097948bd76e41e0..6e364a19ddf460b90c2d405edcf05593afa57925 100644 (file)
@@ -86,6 +86,8 @@ php_oci_descriptor *php_oci_lob_create (php_oci_connection *connection, long typ
        descriptor->lob_current_position = 0;
        descriptor->lob_size = -1;                              /* we should set it to -1 to know, that it's just not initialized */
        descriptor->buffering = PHP_OCI_LOB_BUFFER_DISABLED;                            /* buffering is off by default */
+       descriptor->charset_form = SQLCS_IMPLICIT;      /* default value */
+       descriptor->charset_id = connection->charset;
 
        if (descriptor->type == OCI_DTYPE_LOB || descriptor->type == OCI_DTYPE_FILE) {
                /* add Lobs & Files to hash. we'll flush them at the end */
@@ -309,8 +311,8 @@ int php_oci_lob_read (php_oci_descriptor *descriptor, long read_length, long ini
                        OCI_FIRST_PIECE,
                        (dvoid *)&ctx,
                        (OCICallbackLobRead2) php_oci_lob_callback,             /* callback... */
-                       (ub2) connection->charset,              /* The character set ID of the buffer data. */
-                       (ub1) SQLCS_IMPLICIT                    /* The character set form of the buffer data. */
+                       (ub2) descriptor->charset_id,              /* The character set ID of the buffer data. */
+                       (ub1) descriptor->charset_form                    /* The character set form of the buffer data. */
                )
        );
        
@@ -340,8 +342,8 @@ int php_oci_lob_read (php_oci_descriptor *descriptor, long read_length, long ini
                         (ub4) buffer_size,                          /* size of buffer */
                         (dvoid *)&ctx,
                         (OCICallbackLobRead) php_oci_lob_callback,              /* callback... */
-                        (ub2) connection->charset,              /* The character set ID of the buffer data. */
-                        (ub1) SQLCS_IMPLICIT                    /* The character set form of the buffer data. */
+                        (ub2) descriptor->charset_id,              /* The character set ID of the buffer data. */
+                        (ub1) descriptor->charset_form                    /* The character set form of the buffer data. */
                )
        );
        
@@ -353,8 +355,10 @@ int php_oci_lob_read (php_oci_descriptor *descriptor, long read_length, long ini
        if (connection->errcode != OCI_SUCCESS) {
                php_oci_error(connection->err, connection->errcode TSRMLS_CC);
                PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
-               efree(*data);
-               *data = NULL;
+               if (*data) {
+                       efree(*data);
+                       *data = NULL;
+               }
                *data_len = 0;
                return 1;
        }
@@ -367,8 +371,10 @@ int php_oci_lob_read (php_oci_descriptor *descriptor, long read_length, long ini
                if (connection->errcode != OCI_SUCCESS) {
                        php_oci_error(connection->err, connection->errcode TSRMLS_CC);
                        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
-                       efree(*data);
-                       *data = NULL;
+                       if (*data) {
+                               efree(*data);
+                               *data = NULL;
+                       }
                        *data_len = 0;
                        return 1;
                }
@@ -402,7 +408,22 @@ int php_oci_lob_write (php_oci_descriptor *descriptor, ub4 offset, char *data, i
                offset = descriptor->lob_current_position;
        }
        
-       connection->errcode = PHP_OCI_CALL(OCILobWrite, (connection->svc, connection->err, lob, (ub4 *)&data_len, (ub4) offset + 1, (dvoid *) data, (ub4) data_len, OCI_ONE_PIECE, (dvoid *)0, (OCICallbackLobWrite) 0, (ub2) 0, (ub1) SQLCS_IMPLICIT));
+       connection->errcode = PHP_OCI_CALL(OCILobWrite, 
+                       (
+                               connection->svc, 
+                               connection->err, 
+                               lob, 
+                               (ub4 *)&data_len, 
+                               (ub4) offset + 1, 
+                               (dvoid *) data, 
+                               (ub4) data_len, 
+                               OCI_ONE_PIECE, 
+                               (dvoid *)0, 
+                               (OCICallbackLobWrite) 0, 
+                               (ub2) descriptor->charset_id, 
+                               (ub1) descriptor->charset_form
+                       )
+               );
 
        if (connection->errcode) {
                php_oci_error(connection->err, connection->errcode TSRMLS_CC);
@@ -643,8 +664,8 @@ int php_oci_lob_import (php_oci_descriptor *descriptor, char *filename TSRMLS_DC
                                        OCI_ONE_PIECE, 
                                        (dvoid *)0, 
                                        (OCICallbackLobWrite) 0, 
-                                       (ub2) 0
-                                       (ub1) SQLCS_IMPLICIT
+                                       (ub2) descriptor->charset_id
+                                       (ub1) descriptor->charset_form
                                )
                );
 
index 19f2d2c376aa32b9cafd3f8d67d42bf3aa01e7ca..5186b33d9f9e0276c077f0ea7060529c4ccfe233 100644 (file)
@@ -388,6 +388,26 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC)
                                return 1;
                        }
 
+                       /* get character set form  */
+                       statement->errcode = PHP_OCI_CALL(OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->charset_form, (ub4 *)0, OCI_ATTR_CHARSET_FORM, statement->err));
+
+                       if (statement->errcode != OCI_SUCCESS) {
+                               PHP_OCI_CALL(OCIDescriptorFree, (param, OCI_DTYPE_PARAM));
+                               php_oci_error(statement->err, statement->errcode TSRMLS_CC);
+                               PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode);
+                               return 1;
+                       }
+       
+                       /* get character set id  */
+                       statement->errcode = PHP_OCI_CALL(OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->charset_id, (ub4 *)0, OCI_ATTR_CHARSET_ID, statement->err));
+
+                       if (statement->errcode != OCI_SUCCESS) {
+                               PHP_OCI_CALL(OCIDescriptorFree, (param, OCI_DTYPE_PARAM));
+                               php_oci_error(statement->err, statement->errcode TSRMLS_CC);
+                               PHP_OCI_HANDLE_ERROR(statement->connection, statement->errcode);
+                               return 1;
+                       }
+       
                        /* get size of the column */
                        statement->errcode = PHP_OCI_CALL(OCIAttrGet, ((dvoid *)param, OCI_DTYPE_PARAM, (dvoid *)&outcol->data_size, (dvoid *)0, OCI_ATTR_DATA_SIZE, statement->err));
                        
@@ -478,6 +498,8 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC)
                                        }
                                        outcol->descid = descr->id;
                                        buf = &(descr->descriptor);
+                                       descr->charset_form = outcol->charset_form;
+                                       descr->charset_id = outcol->charset_id;
                                        break;
 
                                case SQLT_LNG:
index 346abe3ce4ac87c416ea9827111e1822381ef47d..3f12b49737cb59b027c7e9442aa3644a3f0b7482 100644 (file)
@@ -127,6 +127,8 @@ typedef struct { /* php_oci_descriptor {{{ */
        int lob_size;                                   /* cached LOB size. -1 = Lob wasn't initialized yet */
        int buffering;                                  /* cached buffering flag. 0 - off, 1 - on, 2 - on and buffer was used */
        ub4 chunk_size;                                 /* chunk size of the LOB. 0 - unknown */
+       ub1 charset_form;                               /* charset form, required for NCLOBs */
+       ub2 charset_id;                                 /* charset ID */
 } php_oci_descriptor; /* }}} */
 
 typedef struct { /* php_oci_lob_ctx {{{ */
@@ -212,6 +214,8 @@ typedef struct { /* php_oci_out_column {{{ */
        ub4 cb_retlen;                                  /* */
        ub2 scale;                                              /* column scale */
        ub2 precision;                                  /* column precision */
+       ub1 charset_form;                               /* charset form, required for NCLOBs */
+       ub2 charset_id;                                 /* charset ID */
 } php_oci_out_column; /* }}} */
 
 /* {{{ macros */
diff --git a/ext/oci8/tests/bug35973.phpt b/ext/oci8/tests/bug35973.phpt
new file mode 100644 (file)
index 0000000..b62f5cf
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+bug #35973 (Error ORA-24806 occurs when trying to fetch a NCLOB field)
+--SKIPIF--
+<?php if (!extension_loaded("oci8")) print "skip"; ?>
+--FILE--
+<?php
+
+require dirname(__FILE__).'/connect.inc';
+
+$s1 = oci_parse($c, "drop table test_nclob");
+@oci_execute($s1);
+
+$s2 = oci_parse($c, "create table test_nclob (nc NCLOB)");
+oci_execute($s2);
+
+$s3 = oci_parse($c, "insert into test_nclob (nc) values ('12345data')");
+oci_execute($s3);
+
+$s3 = oci_parse($c, "select * from test_nclob");
+oci_execute($s3);
+
+var_dump($data = oci_fetch_assoc($s3));
+$d = $data['NC'];
+
+var_dump($d->read(5));
+var_dump($d->read(4));
+
+$s1 = oci_parse($c, "drop table test_nclob");
+@oci_execute($s1);
+
+echo "Done\n";
+?>
+--EXPECTF--    
+array(1) {
+  ["NC"]=>
+  object(OCI-Lob)#%d (1) {
+    ["descriptor"]=>
+    resource(%d) of type (oci8 descriptor)
+  }
+}
+string(%d) "%s5"
+string(%d) "%sa"
+Done