tony2001 Wed Apr 5 14:07:16 2006 UTC
Modified files:
/php-src/ext/oci8 config.m4 oci8_lob.c php_oci8_int.h
Log:
fix #36934 (OCILob->read() doesn't move internal pointer when reading 0's)
no support for Unicode CLOBs in Oracle < 10, sorry.
http://cvs.php.net/viewcvs.cgi/php-src/ext/oci8/config.m4?r1=1.58&r2=1.59&diff_format=u
Index: php-src/ext/oci8/config.m4
diff -u php-src/ext/oci8/config.m4:1.58 php-src/ext/oci8/config.m4:1.59
--- php-src/ext/oci8/config.m4:1.58 Fri Jan 20 16:58:33 2006
+++ php-src/ext/oci8/config.m4 Wed Apr 5 14:07:16 2006
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.58 2006/01/20 16:58:33 tony2001 Exp $
+dnl $Id: config.m4,v 1.59 2006/04/05 14:07:16 tony2001 Exp $
dnl
if test -z "$SED"; then
@@ -232,6 +232,13 @@
], [], [
-L$OCI8_DIR/$OCI8_LIB_DIR $OCI8_SHARED_LIBADD
])
+
+ PHP_CHECK_LIBRARY(clntsh, OCILobRead2,
+ [
+ AC_DEFINE(HAVE_OCI_LOB_READ2,1,[ ])
+ ], [], [
+ -L$OCI8_DIR/$OCI8_LIB_DIR $OCI8_SHARED_LIBADD
+ ])
;;
@@ -242,6 +249,7 @@
AC_DEFINE(HAVE_OCI_ENV_NLS_CREATE,1,[ ])
AC_DEFINE(HAVE_OCI_ENV_CREATE,1,[ ])
AC_DEFINE(HAVE_OCI_STMT_PREPARE2,1,[ ])
+ AC_DEFINE(HAVE_OCI_LOB_READ2,1,[ ])
AC_DEFINE(HAVE_OCI8_TEMP_LOB,1,[ ])
AC_DEFINE(PHP_OCI8_HAVE_COLLECTIONS,1,[ ])
;;
@@ -354,6 +362,7 @@
AC_DEFINE(HAVE_OCI_ENV_NLS_CREATE,1,[ ])
AC_DEFINE(HAVE_OCI_ENV_CREATE,1,[ ])
AC_DEFINE(HAVE_OCI_STMT_PREPARE2,1,[ ])
+ AC_DEFINE(HAVE_OCI_LOB_READ2,1,[ ])
AC_DEFINE(HAVE_OCI8_TEMP_LOB,1,[ ])
AC_DEFINE(PHP_OCI8_HAVE_COLLECTIONS,1,[ ])
http://cvs.php.net/viewcvs.cgi/php-src/ext/oci8/oci8_lob.c?r1=1.11&r2=1.12&diff_format=u
Index: php-src/ext/oci8/oci8_lob.c
diff -u php-src/ext/oci8/oci8_lob.c:1.11 php-src/ext/oci8/oci8_lob.c:1.12
--- php-src/ext/oci8/oci8_lob.c:1.11 Tue Mar 21 15:07:14 2006
+++ php-src/ext/oci8/oci8_lob.c Wed Apr 5 14:07:16 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oci8_lob.c,v 1.11 2006/03/21 15:07:14 tony2001 Exp $ */
+/* $Id: oci8_lob.c,v 1.12 2006/04/05 14:07:16 tony2001 Exp $ */
@@ -150,8 +150,11 @@
{
php_oci_connection *connection = descriptor->connection;
ub4 length = 0;
- int bytes_read, bytes_total = 0, offset = 0, data_len_chars = 0;
+ int bytes_read, bytes_total = 0, offset = 0;
int requested_len = read_length; /* this is by default */
+#if defined(HAVE_OCI_LOB_READ2)
+ int chars_read = 0, is_clob = 0;
+#endif
*data_len = 0;
*data = NULL;
@@ -190,6 +193,23 @@
return 1;
}
}
+#ifdef HAVE_OCI_LOB_READ2
+ else {
+ ub2 charset_id = 0;
+
+ connection->errcode = PHP_OCI_CALL(OCILobCharSetId,
(connection->env, connection->err, descriptor->descriptor, &charset_id));
+
+ if (connection->errcode != OCI_SUCCESS) {
+ php_oci_error(connection->err, connection->errcode
TSRMLS_CC);
+ PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
+ return 1;
+ }
+
+ if (charset_id > 0) { /* charset_id is always > 0 for [N]CLOBs
*/
+ is_clob = 1;
+ }
+ }
+#endif
*data = (char *)emalloc(requested_len + 1);
bytes_read = requested_len;
@@ -198,7 +218,46 @@
/* TODO
* We need to make sure this function works with Unicode LOBs
* */
-
+
+#if defined(HAVE_OCI_LOB_READ2)
+
+ do {
+ chars_read = 0;
+ connection->errcode = PHP_OCI_CALL(OCILobRead2,
+ (
+ connection->svc,
+ connection->err,
+ descriptor->descriptor,
+ (oraub8 *)&bytes_read,
/* IN/OUT bytes toread/read */
+ (oraub8 *)&chars_read,
+ (oraub8) offset + 1,
/* offset (starts with 1) */
+ (dvoid *) ((char *) *data + *data_len),
+ (oraub8) requested_len,
/* size of buffer */
+ 0,
+ NULL,
+ (OCICallbackLobRead2) 0,
/* callback... */
+ (ub2) connection->charset, /* The
character set ID of the buffer data. */
+ (ub1) SQLCS_IMPLICIT
/* The character set form of the buffer data. */
+ )
+ );
+
+ bytes_total += bytes_read;
+ if (is_clob) {
+ offset += chars_read;
+ } else {
+ offset += bytes_read;
+ }
+
+ *data_len += bytes_read;
+
+ if (connection->errcode != OCI_NEED_DATA) {
+ break;
+ }
+ *data = erealloc(*data, *data_len + PHP_OCI_LOB_BUFFER_SIZE +
1);
+ } while (connection->errcode == OCI_NEED_DATA);
+
+#else
+
do {
connection->errcode = PHP_OCI_CALL(OCILobRead,
(
@@ -217,11 +276,7 @@
);
bytes_total += bytes_read;
- /*
- * Oracle doesn't tell use how many CHARS were read,
- * so we have to count them to get the correct offset for CLOBS
*/
- data_len_chars = OCIMultiByteStrnDisplayLength(connection->env,
*data, bytes_total);
- offset = initial_offset + data_len_chars;
+ offset += bytes_read;
*data_len += bytes_read;
@@ -231,6 +286,8 @@
*data = erealloc(*data, *data_len + PHP_OCI_LOB_BUFFER_SIZE +
1);
} while (connection->errcode == OCI_NEED_DATA);
+#endif
+
if (connection->errcode != OCI_SUCCESS) {
php_oci_error(connection->err, connection->errcode TSRMLS_CC);
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
@@ -239,7 +296,7 @@
return 1;
}
- descriptor->lob_current_position += data_len_chars;
+ descriptor->lob_current_position = offset;
if (descriptor->type == OCI_DTYPE_FILE) {
connection->errcode = PHP_OCI_CALL(OCILobFileClose,
(connection->svc, connection->err, descriptor->descriptor));
http://cvs.php.net/viewcvs.cgi/php-src/ext/oci8/php_oci8_int.h?r1=1.14&r2=1.15&diff_format=u
Index: php-src/ext/oci8/php_oci8_int.h
diff -u php-src/ext/oci8/php_oci8_int.h:1.14
php-src/ext/oci8/php_oci8_int.h:1.15
--- php-src/ext/oci8/php_oci8_int.h:1.14 Tue Jan 31 18:36:59 2006
+++ php-src/ext/oci8/php_oci8_int.h Wed Apr 5 14:07:16 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_oci8_int.h,v 1.14 2006/01/31 18:36:59 tony2001 Exp $ */
+/* $Id: php_oci8_int.h,v 1.15 2006/04/05 14:07:16 tony2001 Exp $ */
#if HAVE_OCI8
# ifndef PHP_OCI8_INT_H
@@ -78,7 +78,7 @@
#define PHP_OCI_MAX_NAME_LEN 64
#define PHP_OCI_MAX_DATA_SIZE INT_MAX
#define PHP_OCI_PIECE_SIZE (64*1024)-1
-#define PHP_OCI_LOB_BUFFER_SIZE 1048576l
+#define PHP_OCI_LOB_BUFFER_SIZE 32768
#define PHP_OCI_ASSOC 1<<0
#define PHP_OCI_NUM 1<<1
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php