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 */
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. */
)
);
(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. */
)
);
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;
}
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;
}
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);
OCI_ONE_PIECE,
(dvoid *)0,
(OCICallbackLobWrite) 0,
- (ub2) 0,
- (ub1) SQLCS_IMPLICIT
+ (ub2) descriptor->charset_id,
+ (ub1) descriptor->charset_form
)
);
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));
}
outcol->descid = descr->id;
buf = &(descr->descriptor);
+ descr->charset_form = outcol->charset_form;
+ descr->charset_id = outcol->charset_id;
break;
case SQLT_LNG:
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 {{{ */
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 */
--- /dev/null
+--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