コード例 #1
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_temp_lob_close()
   Close Temporary LOB */
int php_oci_temp_lob_close (php_oci_descriptor *descriptor)
{
	php_oci_connection *connection = descriptor->connection;
	int is_temporary;
	sword errstatus;

	PHP_OCI_CALL_RETURN(errstatus, OCILobIsTemporary, (connection->env,connection->err, descriptor->descriptor, &is_temporary));
	
	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	
	if (is_temporary) {
		PHP_OCI_CALL_RETURN(errstatus, OCILobFreeTemporary, (connection->svc, connection->err, descriptor->descriptor));
		
		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return 1;
		}
	}
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #2
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_element_set_string()
 Change element's value to the given string */
int php_oci_collection_element_set_string(php_oci_collection *collection, zend_long index, char *element, int element_len)
{
    OCIInd new_index = OCI_IND_NOTNULL;
    OCIString *ocistr = (OCIString *)0;
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    PHP_OCI_CALL_RETURN(errstatus, OCIStringAssignText, (connection->env, connection->err, (CONST oratext *)element, element_len, &ocistr));

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    PHP_OCI_CALL_RETURN(errstatus, OCICollAssignElem,
                        (
                            connection->env,
                            connection->err,
                            (ub4)index,
                            (dvoid *) ocistr,
                            (dvoid *) &new_index,
                            (OCIColl *) collection->collection
                        )
                       );

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #3
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_write_tmp()
 Create temporary LOB and write data to it */
int php_oci_lob_write_tmp (php_oci_descriptor *descriptor, zend_long type, char *data, int data_len)
{
	php_oci_connection *connection = descriptor->connection;
	OCILobLocator *lob		   = descriptor->descriptor;
	ub4 bytes_written = 0;
	sword errstatus;
	
	switch (type) {
		case OCI_TEMP_BLOB:
		case OCI_TEMP_CLOB:
			/* only these two are allowed */
			break;
		default:
			php_error_docref(NULL, E_WARNING, "Invalid temporary lob type: %pd", type);
			return 1;
			break;
	}

	if (data_len < 0) {
		return 1;
	}

	PHP_OCI_CALL_RETURN(errstatus, OCILobCreateTemporary,
			(
			 connection->svc,
			 connection->err,
			 lob,
			 OCI_DEFAULT,
			 OCI_DEFAULT,
			 (ub1)type,
			 OCI_ATTR_NOCACHE,
			 OCI_DURATION_SESSION
			)
	);

	if (errstatus) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}

	PHP_OCI_CALL_RETURN(errstatus, OCILobOpen, (connection->svc, connection->err, lob, OCI_LOB_READWRITE));

	if (errstatus) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}

	descriptor->is_open = 1;
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */

	return php_oci_lob_write(descriptor, 0, data, data_len, &bytes_written);
}
コード例 #4
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_set_buffering()
 Turn buffering off/onn for this particular LOB */
int php_oci_lob_set_buffering (php_oci_descriptor *descriptor, int on_off)
{
	php_oci_connection *connection = descriptor->connection;
	sword errstatus;

	if (!on_off && descriptor->buffering == PHP_OCI_LOB_BUFFER_DISABLED) {
		/* disabling when it's already off */
		return 0;
	}
	
	if (on_off && descriptor->buffering != PHP_OCI_LOB_BUFFER_DISABLED) {
		/* enabling when it's already on */
		return 0;
	}
	
	if (on_off) {
		PHP_OCI_CALL_RETURN(errstatus, OCILobEnableBuffering, (connection->svc, connection->err, descriptor->descriptor));
	} else {
		PHP_OCI_CALL_RETURN(errstatus, OCILobDisableBuffering, (connection->svc, connection->err, descriptor->descriptor));
	}

	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	descriptor->buffering = on_off ? PHP_OCI_LOB_BUFFER_ENABLED : PHP_OCI_LOB_BUFFER_DISABLED;
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #5
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_erase()
 Erase (or fill with whitespaces, depending on LOB type) the LOB (or its part) */
int php_oci_lob_erase (php_oci_descriptor *descriptor, zend_long offset, ub4 length, ub4 *bytes_erased)
{
	php_oci_connection *connection = descriptor->connection;
	OCILobLocator *lob = descriptor->descriptor;
	ub4 lob_length;
	sword errstatus;

	*bytes_erased = 0;
	
	if (php_oci_lob_get_length(descriptor, &lob_length)) {
		return 1;
	}
	
	if (offset == -1) {
		offset = descriptor->lob_current_position;
	}

	if (length == -1) {
		length = lob_length;
	}
	
	PHP_OCI_CALL_RETURN(errstatus, OCILobErase, (connection->svc, connection->err, lob, (ub4 *)&length, (ub4) offset+1));

	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	
	*bytes_erased = length;
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #6
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_calculate_buffer() 
   Work out the size for LOB buffering */
static inline int php_oci_lob_calculate_buffer(php_oci_descriptor *descriptor, zend_long read_length)
{
	php_oci_connection *connection = descriptor->connection;
	ub4 chunk_size;
	sword errstatus;

	if (descriptor->type == OCI_DTYPE_FILE) {
		return (int) read_length;
	}

	if (!descriptor->chunk_size) {
		PHP_OCI_CALL_RETURN(errstatus, OCILobGetChunkSize, (connection->svc, connection->err, descriptor->descriptor, &chunk_size));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return (int) read_length; /* we have to return original length here */
		}
		descriptor->chunk_size = chunk_size;
		connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	}
	
	if ((read_length % descriptor->chunk_size) != 0) {
		return (int) descriptor->chunk_size * (((int) read_length / descriptor->chunk_size) + 1);
	}
	return (int) read_length;
}
コード例 #7
0
ファイル: oci8_lob.c プロジェクト: NobleGaz/PHP
/* {{{ php_oci_lob_create()
 Create LOB descriptor and allocate all the resources needed */
php_oci_descriptor *php_oci_lob_create (php_oci_connection *connection, long type TSRMLS_DC)
{
	php_oci_descriptor *descriptor;

	switch (type) {
		case OCI_DTYPE_FILE:
		case OCI_DTYPE_LOB:
		case OCI_DTYPE_ROWID:
			/* these three are allowed */
			break;
		default:
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown descriptor type %ld", type);
			return NULL;
			break;
	}

	descriptor = ecalloc(1, sizeof(php_oci_descriptor));
	descriptor->type = type;
	descriptor->connection = connection;
	zend_list_addref(descriptor->connection->rsrc_id);

	PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIDescriptorAlloc, (connection->env, (dvoid*)&(descriptor->descriptor), descriptor->type, (size_t) 0, (dvoid **) 0));

	if (OCI_G(errcode) != OCI_SUCCESS) {
		OCI_G(errcode) = php_oci_error(OCI_G(err), OCI_G(errcode) TSRMLS_CC);
		PHP_OCI_HANDLE_ERROR(connection, OCI_G(errcode));
		efree(descriptor);
		return NULL;
	}

	PHP_OCI_REGISTER_RESOURCE(descriptor, le_descriptor);
	
	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;
	descriptor->is_open = 0;

	if (descriptor->type == OCI_DTYPE_LOB || descriptor->type == OCI_DTYPE_FILE) {
		/* add Lobs & Files to hash. we'll flush them at the end */
		if (!connection->descriptors) {
			ALLOC_HASHTABLE(connection->descriptors);
			zend_hash_init(connection->descriptors, 0, NULL, php_oci_descriptor_flush_hash_dtor, 0);
			connection->descriptor_count = 0;
		}
		
		descriptor->index = (connection->descriptor_count)++;
		if (connection->descriptor_count == LONG_MAX) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal descriptor counter has reached limit");
			php_oci_connection_descriptors_free(connection TSRMLS_CC);
			return NULL;
		}

		zend_hash_index_update(connection->descriptors,descriptor->index,&descriptor,sizeof(php_oci_descriptor *),NULL);
	}
	return descriptor;

} /* }}} */
コード例 #8
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_get_length()
 Get length of the LOB. The length is cached so we don't need to ask Oracle every time */
int php_oci_lob_get_length (php_oci_descriptor *descriptor, ub4 *length)
{
	php_oci_connection *connection = descriptor->connection;
	sword errstatus;

	*length = 0;
	
	if (descriptor->lob_size >= 0) {
		*length = descriptor->lob_size;
		return 0;
	} else {
		if (descriptor->type == OCI_DTYPE_FILE) {
			PHP_OCI_CALL_RETURN(errstatus, OCILobFileOpen, (connection->svc, connection->err, descriptor->descriptor, OCI_FILE_READONLY));
			if (errstatus != OCI_SUCCESS) {
				connection->errcode = php_oci_error(connection->err, errstatus);
				PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
				return 1;
			}
		}
		
		PHP_OCI_CALL_RETURN(errstatus, OCILobGetLength, (connection->svc, connection->err, descriptor->descriptor, (ub4 *)length));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return 1;
		}

		descriptor->lob_size = *length;

		if (descriptor->type == OCI_DTYPE_FILE) {
			PHP_OCI_CALL_RETURN(errstatus, OCILobFileClose, (connection->svc, connection->err, descriptor->descriptor));

			if (errstatus != OCI_SUCCESS) {
				connection->errcode = php_oci_error(connection->err, errstatus);
				PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
				return 1;
			}
		}

		connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	}
	return 0;	
}
コード例 #9
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_element_set_number()
 Change element's value to the given NUMBER */
int php_oci_collection_element_set_number(php_oci_collection *collection, zend_long index, char *number, int number_len)
{
    OCIInd new_index = OCI_IND_NOTNULL;
    double element_double;
    OCINumber oci_number;
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    element_double = zend_strtod(number, NULL);

    PHP_OCI_CALL_RETURN(errstatus, OCINumberFromReal, (connection->err, &element_double, sizeof(double), &oci_number));

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    PHP_OCI_CALL_RETURN(errstatus, OCICollAssignElem,
                        (
                            connection->env,
                            connection->err,
                            (ub4) index,
                            (dvoid *) &oci_number,
                            (dvoid *) &new_index,
                            (OCIColl *) collection->collection
                        )
                       );

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #10
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_element_set_date()
 Change element's value to the given DATE */
int php_oci_collection_element_set_date(php_oci_collection *collection, zend_long index, char *date, int date_len)
{
    OCIInd new_index = OCI_IND_NOTNULL;
    OCIDate oci_date;
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    /* format and language are NULLs, so format is "DD-MON-YY" and language is the default language of the session */
    PHP_OCI_CALL_RETURN(errstatus, OCIDateFromText, (connection->err, (CONST text *)date, date_len, NULL, 0, NULL, 0, &oci_date));

    if (errstatus != OCI_SUCCESS) {
        /* failed to convert string to date */
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    PHP_OCI_CALL_RETURN(errstatus, OCICollAssignElem,
                        (
                            connection->env,
                            connection->err,
                            (ub4)index,
                            (dvoid *) &oci_date,
                            (dvoid *) &new_index,
                            (OCIColl *) collection->collection
                        )
                       );

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #11
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_size()
 Return size of the collection */
int php_oci_collection_size(php_oci_collection *collection, sb4 *size)
{
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    PHP_OCI_CALL_RETURN(errstatus, OCICollSize, (connection->env, connection->err, collection->collection, (sb4 *)size));

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }
    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #12
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_trim()
 Trim collection to the given number of elements */
int php_oci_collection_trim(php_oci_collection *collection, zend_long trim_size)
{
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    PHP_OCI_CALL_RETURN(errstatus, OCICollTrim, (connection->env, connection->err, trim_size, collection->collection));

    if (errstatus != OCI_SUCCESS) {
        errstatus = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }
    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #13
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_assign()
 Assigns a value to the collection from another collection */
int php_oci_collection_assign(php_oci_collection *collection_dest, php_oci_collection *collection_from)
{
    php_oci_connection *connection = collection_dest->connection;
    sword errstatus;

    PHP_OCI_CALL_RETURN(errstatus, OCICollAssign, (connection->env, connection->err, collection_from->collection, collection_dest->collection));

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }
    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #14
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_element_set_null()
 Set the element with the given index to NULL */
int php_oci_collection_element_set_null(php_oci_collection *collection, zend_long index)
{
    OCIInd null_index = OCI_IND_NULL;
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    /* set NULL element */
    PHP_OCI_CALL_RETURN(errstatus, OCICollAssignElem, (connection->env, connection->err, (ub4) index, (dvoid *)"", &null_index, collection->collection));

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }
    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #15
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_is_equal()
 Compare two LOB descriptors and figure out if they are pointing to the same LOB */
int php_oci_lob_is_equal (php_oci_descriptor *descriptor_first, php_oci_descriptor *descriptor_second, boolean *result)
{
	php_oci_connection *connection = descriptor_first->connection;
	OCILobLocator *first_lob   = descriptor_first->descriptor;
	OCILobLocator *second_lob  = descriptor_second->descriptor;
	sword errstatus;

	PHP_OCI_CALL_RETURN(errstatus, OCILobIsEqual, (connection->env, first_lob, second_lob, result));

	if (errstatus) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #16
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_append_null()
 Append NULL element to the end of the collection */
int php_oci_collection_append_null(php_oci_collection *collection)
{
    OCIInd null_index = OCI_IND_NULL;
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    /* append NULL element */
    PHP_OCI_CALL_RETURN(errstatus, OCICollAppend, (connection->env, connection->err, (dvoid *)0, &null_index, collection->collection));

    if (errstatus != OCI_SUCCESS) {
        errstatus = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }
    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
    return 0;
}
コード例 #17
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_copy()
 Copy one LOB (or its part) to another one */
int php_oci_lob_copy (php_oci_descriptor *descriptor_dest, php_oci_descriptor *descriptor_from, zend_long length)
{
	php_oci_connection *connection = descriptor_dest->connection;
	ub4 length_dest, length_from, copy_len;
	sword errstatus;
	
	if (php_oci_lob_get_length(descriptor_dest, &length_dest)) {
		return 1;
	}
	
	if (php_oci_lob_get_length(descriptor_from, &length_from)) {
		return 1;
	}

	if (length == -1) {
		copy_len = length_from - descriptor_from->lob_current_position;
	} else {
		copy_len = (ub4) length;
	}

	if ((int)copy_len <= 0) {
		/* silently fail, there is nothing to copy */
		return 1;
	}

	PHP_OCI_CALL_RETURN(errstatus, OCILobCopy,
			(
			 connection->svc,
			 connection->err,
			 descriptor_dest->descriptor,
			 descriptor_from->descriptor,
			 copy_len,
			 descriptor_dest->lob_current_position+1,
			 descriptor_from->lob_current_position+1
			)
	);

	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #18
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_close()
 Destroy collection and all associated resources */
void php_oci_collection_close(php_oci_collection *collection)
{
    php_oci_connection *connection = collection->connection;
    sword errstatus;

    if (collection->collection) {
        PHP_OCI_CALL_RETURN(errstatus, OCIObjectFree, (connection->env, connection->err, (dvoid *)collection->collection, (ub2)OCI_OBJECTFREE_FORCE));

        if (errstatus != OCI_SUCCESS) {
            connection->errcode = php_oci_error(connection->err, errstatus);
            PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        } else {
            connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
        }
    }

    zend_list_delete(collection->connection->id);
    efree(collection);
    return;
}
コード例 #19
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_flush()
 Flush buffers for the LOB (only if they have been used) */
int php_oci_lob_flush(php_oci_descriptor *descriptor, zend_long flush_flag)
{
	OCILobLocator *lob = descriptor->descriptor;
	php_oci_connection *connection = descriptor->connection;
	sword errstatus;

	if (!lob) {
		return 1;
	}

	switch (flush_flag) {
		case 0:
		case OCI_LOB_BUFFER_FREE:
			/* only these two are allowed */
			break;
		default:
			php_error_docref(NULL, E_WARNING, "Invalid flag value: %pd", flush_flag);
			return 1;
			break;
	}
	
	/* do not really flush buffer, but report success
	 * to suppress OCI error when flushing not used buffer
	 * */
	if (descriptor->buffering != PHP_OCI_LOB_BUFFER_USED) {
		return 0;
	}

	PHP_OCI_CALL_RETURN(errstatus, OCILobFlushBuffer, (connection->svc, connection->err, lob, (ub4) flush_flag));

	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}

	/* marking buffer as enabled and not used */
	descriptor->buffering = PHP_OCI_LOB_BUFFER_ENABLED;
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #20
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_close()
 Close LOB */
int php_oci_lob_close (php_oci_descriptor *descriptor)
{
	php_oci_connection *connection = descriptor->connection;
	sword errstatus;

	if (descriptor->is_open) {
		PHP_OCI_CALL_RETURN(errstatus, OCILobClose, (connection->svc, connection->err, descriptor->descriptor));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return 1;
		}
		connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	}

	if (php_oci_temp_lob_close(descriptor)) {
		return 1;
	}
	
	return 0;
}
コード例 #21
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_truncate()
 Truncate LOB to the given length */
int php_oci_lob_truncate (php_oci_descriptor *descriptor, zend_long new_lob_length)
{
	php_oci_connection *connection = descriptor->connection;
	OCILobLocator *lob = descriptor->descriptor;
	ub4 lob_length;
	sword errstatus;
	
	if (php_oci_lob_get_length(descriptor, &lob_length)) {
		return 1;
	}
	
	if (lob_length <= 0) {
		return 0;
	}

	if (new_lob_length < 0) {
		php_error_docref(NULL, E_WARNING, "Size must be greater than or equal to 0");
		return 1;
	}

	if (new_lob_length > lob_length) {
		php_error_docref(NULL, E_WARNING, "Size must be less than or equal to the current LOB size");
		return 1;
	}
	
	PHP_OCI_CALL_RETURN(errstatus, OCILobTrim, (connection->svc, connection->err, lob, (ub4) new_lob_length));

	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	
	descriptor->lob_size = (ub4) new_lob_length;
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */

	return 0;
}
コード例 #22
0
ファイル: oci8_collection.c プロジェクト: Tyrael/php-src
/* {{{ php_oci_collection_element_get()
 Get the element with the given index */
int php_oci_collection_element_get(php_oci_collection *collection, zend_long index, zval *result_element)
{
    php_oci_connection *connection = collection->connection;
    dvoid *element;
    OCIInd *element_index;
    boolean exists;
    oratext buff[1024];
    ub4 buff_len = 1024;
    sword errstatus;

    ZVAL_NULL(result_element);

    connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */

    PHP_OCI_CALL_RETURN(errstatus, OCICollGetElem,
                        (
                            connection->env,
                            connection->err,
                            collection->collection,
                            (ub4)index,
                            &exists,
                            &element,
                            (dvoid **)&element_index
                        )
                       );

    if (errstatus != OCI_SUCCESS) {
        connection->errcode = php_oci_error(connection->err, errstatus);
        PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
        return 1;
    }

    if (exists == 0) {
        /* element doesn't exist */
        return 1;
    }

    if (*element_index == OCI_IND_NULL) {
        /* this is not an error, we're returning NULL here */
        return 0;
    }

    switch (collection->element_typecode) {
    case OCI_TYPECODE_DATE:
        PHP_OCI_CALL_RETURN(errstatus, OCIDateToText, (connection->err, element, 0, 0, 0, 0, &buff_len, buff));

        if (errstatus != OCI_SUCCESS) {
            connection->errcode = php_oci_error(connection->err, errstatus);
            PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
            return 1;
        }

        ZVAL_STRINGL(result_element, (char *)buff, buff_len);
        Z_STRVAL_P(result_element)[buff_len] = '\0';

        return 0;
        break;

    case OCI_TYPECODE_VARCHAR2:
    {
        OCIString *oci_string = *(OCIString **)element;
        text *str;

        PHP_OCI_CALL_RETURN(str, OCIStringPtr, (connection->env, oci_string));

        if (str) {
            ZVAL_STRING(result_element, (char *)str);
        }
        return 0;
    }
    break;

    case OCI_TYPECODE_UNSIGNED16:						/* UNSIGNED SHORT  */
    case OCI_TYPECODE_UNSIGNED32:						/* UNSIGNED LONG  */
    case OCI_TYPECODE_REAL:								/* REAL	   */
    case OCI_TYPECODE_DOUBLE:							/* DOUBLE  */
    case OCI_TYPECODE_INTEGER:							/* INT	*/
    case OCI_TYPECODE_SIGNED16:							/* SHORT  */
    case OCI_TYPECODE_SIGNED32:							/* LONG	 */
    case OCI_TYPECODE_DECIMAL:							/* DECIMAL	*/
    case OCI_TYPECODE_FLOAT:							/* FLOAT	*/
    case OCI_TYPECODE_NUMBER:							/* NUMBER	*/
    case OCI_TYPECODE_SMALLINT:							/* SMALLINT */
    {
        double double_number;

        PHP_OCI_CALL_RETURN(errstatus, OCINumberToReal, (connection->err, (CONST OCINumber *) element, (uword) sizeof(double), (dvoid *) &double_number));

        if (errstatus != OCI_SUCCESS) {
            connection->errcode = php_oci_error(connection->err, errstatus);
            PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
            return 1;
        }

        ZVAL_DOUBLE(result_element, double_number);

        return 0;
    }
    break;
    default:
        php_error_docref(NULL, E_NOTICE, "Unknown or unsupported type of element: %d", collection->element_typecode);
        return 1;
        break;
    }
    /* never reached */
    return 1;
}
コード例 #23
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_import()
 Import LOB contents from the given file */
int php_oci_lob_import (php_oci_descriptor *descriptor, char *filename)
{
	int fp;
	ub4 loblen;
	OCILobLocator *lob = (OCILobLocator *)descriptor->descriptor;
	php_oci_connection *connection = descriptor->connection;
	char buf[8192];
	ub4 offset = 1;
	sword errstatus;
	
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3) || (PHP_MAJOR_VERSION > 5)
	/* Safe mode has been removed in PHP 5.4 */
	if (php_check_open_basedir(filename)) {
#else
	if ((PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename)) {
#endif
		return 1;
	}
	
	if ((fp = VCWD_OPEN(filename, O_RDONLY|O_BINARY)) == -1) {
		php_error_docref(NULL, E_WARNING, "Can't open file %s", filename);
		return 1;
	}

	while ((loblen = read(fp, &buf, sizeof(buf))) > 0) {	
		PHP_OCI_CALL_RETURN(errstatus,
				OCILobWrite,
				(
					connection->svc,
					connection->err,
					lob,
					&loblen,
					offset,
					(dvoid *) &buf,
					loblen,
					OCI_ONE_PIECE,
					(dvoid *)0,
					(OCICallbackLobWrite) 0,
					(ub2) descriptor->charset_id,
					(ub1) descriptor->charset_form
				)
		);

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			close(fp);
			return 1;
		} else {
			connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
		}
		offset += loblen;
	}
	close(fp);
	
	return 0;
}
 	/* }}} */

/* {{{ php_oci_lob_append()
 Append data to the end of the LOB */
int php_oci_lob_append (php_oci_descriptor *descriptor_dest, php_oci_descriptor *descriptor_from)
{
	php_oci_connection *connection = descriptor_dest->connection;
	OCILobLocator *lob_dest = descriptor_dest->descriptor;
	OCILobLocator *lob_from = descriptor_from->descriptor;
	ub4 dest_len, from_len;
	sword errstatus;

	if (php_oci_lob_get_length(descriptor_dest, &dest_len)) {
		return 1;
	}
	
	if (php_oci_lob_get_length(descriptor_from, &from_len)) {
		return 1;
	}

	if (from_len <= 0) {
		return 0;
	}

	PHP_OCI_CALL_RETURN(errstatus, OCILobAppend, (connection->svc, connection->err, lob_dest, lob_from));

	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		return 1;
	}
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #24
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_write()
 Write data to the LOB */
int php_oci_lob_write (php_oci_descriptor *descriptor, ub4 offset, char *data, int data_len, ub4 *bytes_written)
{
	OCILobLocator *lob		   = (OCILobLocator *) descriptor->descriptor;
	php_oci_connection *connection = (php_oci_connection *) descriptor->connection;
	ub4 lob_length;
	sword errstatus;
	
	*bytes_written = 0;
	if (php_oci_lob_get_length(descriptor, &lob_length)) {
		return 1;
	}
	
	if (!data || data_len <= 0) {
		return 0;
	}
	
	if (offset < 0) {
		offset = 0;
	}
	
	if (offset > descriptor->lob_current_position) {
		offset = descriptor->lob_current_position;
	}
	
	PHP_OCI_CALL_RETURN(errstatus, 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 (errstatus) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		*bytes_written = 0;
		return 1;
	}
	*bytes_written = data_len;
	descriptor->lob_current_position += data_len;
	
	if ((int) descriptor->lob_current_position > (int) descriptor->lob_size) {
		descriptor->lob_size = descriptor->lob_current_position;
	}
	
	/* marking buffer as used */
	if (descriptor->buffering == PHP_OCI_LOB_BUFFER_ENABLED) {
		descriptor->buffering = PHP_OCI_LOB_BUFFER_USED;
	}
	
	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}
コード例 #25
0
/* {{{ php_oci_collection_create()
 Create and return connection handle */
php_oci_collection * php_oci_collection_create(php_oci_connection *connection, char *tdo, int tdo_len, char *schema, int schema_len TSRMLS_DC)
{	
	dvoid *dschp1 = NULL;
	dvoid *parmp1;
	dvoid *parmp2;
	php_oci_collection *collection;
	
	collection = emalloc(sizeof(php_oci_collection));

	collection->connection = connection;
	collection->collection = NULL;
	zend_list_addref(collection->connection->id);

	/* get type handle by name */
	PHP_OCI_CALL_RETURN(connection->errcode, OCITypeByName,
			(
			 connection->env,
			 connection->err,
			 connection->svc,
			 (text *) schema,
			 (ub4) schema_len,
			 (text *) tdo,
			 (ub4) tdo_len,
			 (CONST text *) 0,
			 (ub4) 0,
			 OCI_DURATION_SESSION,
			 OCI_TYPEGET_ALL,
			 &(collection->tdo)
			)
	);

	if (connection->errcode != OCI_SUCCESS) {
		goto CLEANUP;
	}

	/* allocate describe handle */
	PHP_OCI_CALL_RETURN(connection->errcode, OCIHandleAlloc, (connection->env, (dvoid **) &dschp1, (ub4) OCI_HTYPE_DESCRIBE, (size_t) 0, (dvoid **) 0));

	if (connection->errcode != OCI_SUCCESS) {
		goto CLEANUP;
	}

	/* describe TDO */
	PHP_OCI_CALL_RETURN(connection->errcode, OCIDescribeAny,
			(
			 connection->svc,
			 connection->err,
			 (dvoid *) collection->tdo,
			 (ub4) 0,
			 OCI_OTYPE_PTR,
			 (ub1) OCI_DEFAULT,
			 (ub1) OCI_PTYPE_TYPE,
			 dschp1
			)
	);

	if (connection->errcode != OCI_SUCCESS) {
		goto CLEANUP;
	}

	/* get first parameter handle */
	PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet, ((dvoid *) dschp1, (ub4) OCI_HTYPE_DESCRIBE, (dvoid *)&parmp1, (ub4 *)0, (ub4)OCI_ATTR_PARAM, connection->err));

	if (connection->errcode != OCI_SUCCESS) {
		goto CLEANUP;
	}

	/* get the collection type code of the attribute */
	PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
			(
			 (dvoid*) parmp1,
			 (ub4) OCI_DTYPE_PARAM,
			 (dvoid*) &(collection->coll_typecode),
			 (ub4 *) 0,
			 (ub4) OCI_ATTR_COLLECTION_TYPECODE,
			 connection->err
			)
	);

	if (connection->errcode != OCI_SUCCESS) {
		goto CLEANUP;
	}

	switch(collection->coll_typecode) {
		case OCI_TYPECODE_TABLE:
		case OCI_TYPECODE_VARRAY:
			/* get collection element handle */
			PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
					(
					 (dvoid*) parmp1,
					 (ub4) OCI_DTYPE_PARAM,
					 (dvoid*) &parmp2,
					 (ub4 *) 0,
					 (ub4) OCI_ATTR_COLLECTION_ELEMENT,
					 connection->err
					)
			);

			if (connection->errcode != OCI_SUCCESS) {
				goto CLEANUP;
			}

			/* get REF of the TDO for the type */
			PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
					(
					 (dvoid*) parmp2,
					 (ub4) OCI_DTYPE_PARAM,
					 (dvoid*) &(collection->elem_ref),
					 (ub4 *) 0,
					 (ub4) OCI_ATTR_REF_TDO,
					 connection->err
					)
			);

			if (connection->errcode != OCI_SUCCESS) {
				goto CLEANUP;
			}

			/* get the TDO (only header) */
			PHP_OCI_CALL_RETURN(connection->errcode, OCITypeByRef,
					(
					 connection->env,
					 connection->err,
					 collection->elem_ref,
					 OCI_DURATION_SESSION,
					 OCI_TYPEGET_HEADER,
					 &(collection->element_type)
					)
			);

			if (connection->errcode != OCI_SUCCESS) {
				goto CLEANUP;
			}

			/* get typecode */
			PHP_OCI_CALL_RETURN(connection->errcode, OCIAttrGet,
					(
					 (dvoid*) parmp2,
					 (ub4) OCI_DTYPE_PARAM,
					 (dvoid*) &(collection->element_typecode),
					 (ub4 *) 0,
					 (ub4) OCI_ATTR_TYPECODE,
					 connection->err
					)
			);

			if (connection->errcode != OCI_SUCCESS) {
				goto CLEANUP;
			}
			break;
			/* we only support VARRAYs and TABLEs */
		default:
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown collection type %d", collection->coll_typecode);
			break;
	}	

	/* Create object to hold return table */
	PHP_OCI_CALL_RETURN(connection->errcode, OCIObjectNew,
		(
			connection->env,
			connection->err,
			connection->svc,
			OCI_TYPECODE_TABLE,
			collection->tdo,
			(dvoid *)0,
			OCI_DURATION_DEFAULT,
			TRUE,
			(dvoid **) &(collection->collection)
		)
	);

	if (connection->errcode != OCI_SUCCESS) {
		goto CLEANUP;
	}

	/* free the describe handle (Bug #44113) */
	PHP_OCI_CALL(OCIHandleFree, ((dvoid *) dschp1, OCI_HTYPE_DESCRIBE));
	PHP_OCI_REGISTER_RESOURCE(collection, le_collection);
	return collection;
	
CLEANUP:

	if (dschp1) {
		/* free the describe handle (Bug #44113) */
		PHP_OCI_CALL(OCIHandleFree, ((dvoid *) dschp1, OCI_HTYPE_DESCRIBE));
	}
	connection->errcode = php_oci_error(connection->err, connection->errcode TSRMLS_CC);
	PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
	php_oci_collection_close(collection TSRMLS_CC);	
	return NULL;
}
コード例 #26
0
ファイル: oci8_lob.c プロジェクト: rupesh20/php-src
/* {{{ php_oci_lob_read()
 Read specified portion of the LOB into the buffer */
int php_oci_lob_read (php_oci_descriptor *descriptor, zend_long read_length, zend_long initial_offset, char **data, ub4 *data_len)
{
	php_oci_connection *connection = descriptor->connection;
	ub4 length = 0;
	int buffer_size = PHP_OCI_LOB_BUFFER_SIZE;
	php_oci_lob_ctx ctx;
	ub1 *bufp;
	oraub8 bytes_read, offset = 0;
	oraub8 requested_len = read_length; /* this is by default */
	oraub8 chars_read = 0;
	int is_clob = 0;
	sb4 bytes_per_char = 1;
	sword errstatus;

	*data_len = 0;
	*data = NULL;

	ctx.lob_len = data_len;
	ctx.lob_data = data;
	ctx.alloc_len = 0;

	if (php_oci_lob_get_length(descriptor, &length)) {
		return 1;
	}

	if (length <= 0) {
		return 0;
	}
	
	if (initial_offset > length) {
		php_error_docref(NULL, E_WARNING, "Offset must be less than size of the LOB");
		return 1;
	}
		
	if (read_length == -1) {
		requested_len = length;
	}
	
	if ((ub4) requested_len > (length - (ub4) initial_offset)) {
		requested_len = length - initial_offset;
	}
	
	if (requested_len <= 0) {
		return 0;
	}
	
	offset = initial_offset;

	if (descriptor->type == OCI_DTYPE_FILE) {
		PHP_OCI_CALL_RETURN(errstatus, OCILobFileOpen, (connection->svc, connection->err, descriptor->descriptor, OCI_FILE_READONLY));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return 1;
		}
	} else {
		ub2 charset_id = 0;

		PHP_OCI_CALL_RETURN(errstatus, OCILobCharSetId, (connection->env, connection->err, descriptor->descriptor, &charset_id));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return 1;
		}

		if (charset_id > 0) { /* charset_id is always > 0 for [N]CLOBs */
			is_clob = 1;
		}
	}

	if (is_clob) {
		PHP_OCI_CALL_RETURN(errstatus, OCINlsNumericInfoGet, (connection->env, connection->err, &bytes_per_char, OCI_NLS_CHARSET_MAXBYTESZ));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			return 1;
		}
	} else {
		/* BLOBs don't have encoding, so bytes_per_char == 1 */
	}

	ctx.alloc_len = ((ub4) requested_len + 1) * bytes_per_char;
	*data = ecalloc(bytes_per_char, requested_len + 1);

	if (is_clob) {
		chars_read = requested_len;
		bytes_read = 0;
	} else {
		chars_read = 0;
		bytes_read = requested_len;
	}

	buffer_size = ((int) requested_len < buffer_size ) ? (int) requested_len : buffer_size;		/* optimize buffer size */
	buffer_size = php_oci_lob_calculate_buffer(descriptor, buffer_size);	/* use chunk size */

	bufp = (ub1 *) ecalloc(1, buffer_size);
	PHP_OCI_CALL_RETURN(errstatus, OCILobRead2,
		(
			connection->svc,
			connection->err,
			descriptor->descriptor,
			(oraub8 *)&bytes_read,							/* IN/OUT bytes toread/read */
			(oraub8 *)&chars_read,							/* IN/OUT chars toread/read */
			(oraub8) offset + 1,							/* offset (starts with 1) */
			(dvoid *) bufp,
			(oraub8) buffer_size,							/* size of buffer */
			OCI_FIRST_PIECE,
			(dvoid *)&ctx,
			(OCICallbackLobRead2) php_oci_lob_callback,				/* callback... */
			(ub2) descriptor->charset_id,			   /* The character set ID of the buffer data. */
			(ub1) descriptor->charset_form					  /* The character set form of the buffer data. */
		)
	);
	
	efree(bufp);
	
	if (is_clob) {
		offset = descriptor->lob_current_position + chars_read;
	} else {
		offset = descriptor->lob_current_position + bytes_read;
	}
	
	if (errstatus != OCI_SUCCESS) {
		connection->errcode = php_oci_error(connection->err, errstatus);
		PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
		if (*data) {
			efree(*data);
			*data = NULL;
		}
		*data_len = 0;
		return 1;
	}
	
	descriptor->lob_current_position = (int)offset;

	if (descriptor->type == OCI_DTYPE_FILE) {
		PHP_OCI_CALL_RETURN(errstatus, OCILobFileClose, (connection->svc, connection->err, descriptor->descriptor));

		if (errstatus != OCI_SUCCESS) {
			connection->errcode = php_oci_error(connection->err, errstatus);
			PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
			if (*data) {
				efree(*data);
				*data = NULL;
			}
			*data_len = 0;
			return 1;
		}
	}

	connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
	return 0;
}