From e16bd0c0f0422c70114520a9162d448053502f22 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Wed, 9 Aug 2006 15:23:50 +0000 Subject: [PATCH] add support for NCLOBs fix #35973 (Error ORA-24806 occurs when trying to fetch a NCLOB field) --- ext/oci8/oci8_lob.c | 43 +++++++++++++++++++++++++++--------- ext/oci8/oci8_statement.c | 22 ++++++++++++++++++ ext/oci8/php_oci8_int.h | 4 ++++ ext/oci8/tests/bug35973.phpt | 43 ++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 ext/oci8/tests/bug35973.phpt diff --git a/ext/oci8/oci8_lob.c b/ext/oci8/oci8_lob.c index 9e0edc12a3..04e7695f1c 100644 --- a/ext/oci8/oci8_lob.c +++ b/ext/oci8/oci8_lob.c @@ -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 ) ); diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 19f2d2c376..5186b33d9f 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -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: diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h index 346abe3ce4..3f12b49737 100644 --- a/ext/oci8/php_oci8_int.h +++ b/ext/oci8/php_oci8_int.h @@ -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 index 0000000000..b62f5cfd0f --- /dev/null +++ b/ext/oci8/tests/bug35973.phpt @@ -0,0 +1,43 @@ +--TEST-- +bug #35973 (Error ORA-24806 occurs when trying to fetch a NCLOB field) +--SKIPIF-- + +--FILE-- +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 -- 2.40.0