], [], [
-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
+ ])
;;
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,[ ])
;;
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,[ ])
{
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;
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;
/* 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,
(
);
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;
*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);
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));