tony2001 Wed Aug 9 15:23:50 2006 UTC
Added files:
/php-src/ext/oci8/tests bug35973.phpt
Modified files:
/php-src/ext/oci8 oci8_lob.c oci8_statement.c php_oci8_int.h
Log:
add support for NCLOBs
fix #35973 (Error ORA-24806 occurs when trying to fetch a NCLOB field)
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8_lob.c?r1=1.14&r2=1.15&diff_format=u
Index: php-src/ext/oci8/oci8_lob.c
diff -u php-src/ext/oci8/oci8_lob.c:1.14 php-src/ext/oci8/oci8_lob.c:1.15
--- php-src/ext/oci8/oci8_lob.c:1.14 Wed Jun 7 13:36:19 2006
+++ php-src/ext/oci8/oci8_lob.c Wed Aug 9 15:23:50 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oci8_lob.c,v 1.14 2006/06/07 13:36:19 tony2001 Exp $ */
+/* $Id: oci8_lob.c,v 1.15 2006/08/09 15:23:50 tony2001 Exp $ */
@@ -86,6 +86,8 @@
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 @@
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 @@
(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 @@
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 @@
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 @@
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 @@
OCI_ONE_PIECE,
(dvoid *)0,
(OCICallbackLobWrite) 0,
- (ub2) 0,
- (ub1) SQLCS_IMPLICIT
+ (ub2) descriptor->charset_id,
+ (ub1) descriptor->charset_form
)
);
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8_statement.c?r1=1.23&r2=1.24&diff_format=u
Index: php-src/ext/oci8/oci8_statement.c
diff -u php-src/ext/oci8/oci8_statement.c:1.23
php-src/ext/oci8/oci8_statement.c:1.24
--- php-src/ext/oci8/oci8_statement.c:1.23 Wed Aug 9 12:13:30 2006
+++ php-src/ext/oci8/oci8_statement.c Wed Aug 9 15:23:50 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oci8_statement.c,v 1.23 2006/08/09 12:13:30 tony2001 Exp $ */
+/* $Id: oci8_statement.c,v 1.24 2006/08/09 15:23:50 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
@@ -388,6 +388,26 @@
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 @@
}
outcol->descid = descr->id;
buf = &(descr->descriptor);
+ descr->charset_form =
outcol->charset_form;
+ descr->charset_id = outcol->charset_id;
break;
case SQLT_LNG:
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/php_oci8_int.h?r1=1.19&r2=1.20&diff_format=u
Index: php-src/ext/oci8/php_oci8_int.h
diff -u php-src/ext/oci8/php_oci8_int.h:1.19
php-src/ext/oci8/php_oci8_int.h:1.20
--- php-src/ext/oci8/php_oci8_int.h:1.19 Wed Aug 9 12:13:30 2006
+++ php-src/ext/oci8/php_oci8_int.h Wed Aug 9 15:23:50 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_oci8_int.h,v 1.19 2006/08/09 12:13:30 tony2001 Exp $ */
+/* $Id: php_oci8_int.h,v 1.20 2006/08/09 15:23:50 tony2001 Exp $ */
#if HAVE_OCI8
# ifndef PHP_OCI8_INT_H
@@ -127,6 +127,8 @@
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 @@
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 */
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/tests/bug35973.phpt?view=markup&rev=1.1
Index: php-src/ext/oci8/tests/bug35973.phpt
+++ php-src/ext/oci8/tests/bug35973.phpt
--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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php