diff --git a/CHANGELOG.md b/CHANGELOG.md index 349524353..57bb525c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.4.0 + +Features: + +* [joeyhub] Nuked blob, in future objects should not represent types as it gobbles up memory and CPU plus makes the code 10 times larger than it needs to be. + # 1.3.2 Features: diff --git a/ext/config.m4 b/ext/config.m4 index d479d9044..4a13dc28e 100644 --- a/ext/config.m4 +++ b/ext/config.m4 @@ -38,7 +38,6 @@ if test "$PHP_CASSANDRA" != "no"; then src/Aggregate.c \ src/BatchStatement.c \ src/Bigint.c \ - src/Blob.c \ src/Cluster.c \ src/Cluster/Builder.c \ src/Collection.c \ @@ -268,19 +267,19 @@ if test "$PHP_CASSANDRA" != "no"; then PHP_ADD_LIBRARY(m,, CASSANDRA_SHARED_LIBADD) if test "$PHP_CASSANDRA" != "yes"; then - if test -f $PHP_CASSANDRA/include/cassandra.h; then + if test -f $PHP_CASSANDRA/include/cassandra/cassandra.h; then CPP_DRIVER_DIR=$PHP_CASSANDRA fi else for i in /usr/local /usr; do - if test -f $i/include/cassandra.h; then + if test -f $i/include/cassandra/cassandra.h; then CPP_DRIVER_DIR=$i fi done fi AC_MSG_CHECKING([for supported DataStax C/C++ driver version]) - PHP_CASSANDRA_FOUND_CASSANDRA_VERSION=`$AWK '/CASS_VERSION_MAJOR/ {printf $3"."} /CASS_VERSION_MINOR/ {printf $3"."} /CASS_VERSION_PATCH/ {printf $3}' $CPP_DRIVER_DIR/include/cassandra.h` + PHP_CASSANDRA_FOUND_CASSANDRA_VERSION=`$AWK '/CASS_VERSION_MAJOR/ {printf $3"."} /CASS_VERSION_MINOR/ {printf $3"."} /CASS_VERSION_PATCH/ {printf $3}' $CPP_DRIVER_DIR/include/cassandra/cassandra.h` PHP_CASSANDRA_FOUND_CASSANDRA_VERSION_NUMBER=`echo "${PHP_CASSANDRA_FOUND_CASSANDRA_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 100 + [$]2) * 100 + [$]3;}'` if test "$PHP_CASSANDRA_FOUND_CASSANDRA_VERSION_NUMBER" -lt "20700"; then AC_MSG_ERROR([not supported. Driver version 2.7.0+ required (found $PHP_CASSANDRA_FOUND_CASSANDRA_VERSION)]) diff --git a/ext/config.w32 b/ext/config.w32 index a057cdb90..94833896e 100644 --- a/ext/config.w32 +++ b/ext/config.w32 @@ -100,7 +100,6 @@ if (PHP_CASSANDRA != "no") { "Aggregate.c " + "BatchStatement.c " + "Bigint.c " + - "Blob.c " + "Cluster.c " + "Collection.c " + "Column.c " + diff --git a/ext/doc/Cassandra/Blob.php b/ext/doc/Cassandra/Blob.php deleted file mode 100644 index 9ded7f803..000000000 --- a/ext/doc/Cassandra/Blob.php +++ /dev/null @@ -1,61 +0,0 @@ - - - @@ -194,7 +192,6 @@ protocol and Cassandra Query Language v3. - diff --git a/ext/php_driver.c b/ext/php_driver.c index 14b7a31dc..fd6982918 100644 --- a/ext/php_driver.c +++ b/ext/php_driver.c @@ -416,7 +416,6 @@ static PHP_GINIT_FUNCTION(php_driver) php_driver_globals->persistent_sessions = 0; PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_varchar); PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_text); - PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_blob); PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_ascii); PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_bigint); PHP5TO7_ZVAL_UNDEF(php_driver_globals->type_smallint); @@ -485,7 +484,6 @@ PHP_MINIT_FUNCTION(php_driver) php_driver_define_Bigint(TSRMLS_C); php_driver_define_Smallint(TSRMLS_C); php_driver_define_Tinyint(TSRMLS_C); - php_driver_define_Blob(TSRMLS_C); php_driver_define_Decimal(TSRMLS_C); php_driver_define_Float(TSRMLS_C); php_driver_define_Inet(TSRMLS_C); diff --git a/ext/php_driver.h b/ext/php_driver.h index bc42b6fcf..5613dadd5 100644 --- a/ext/php_driver.h +++ b/ext/php_driver.h @@ -6,7 +6,7 @@ #endif #include -#include +#include /* Ensure Visual Studio 2010 does not load MSVC++ stdint definitions */ #ifdef _WIN32 diff --git a/ext/php_driver_types.h b/ext/php_driver_types.h index cc7b751ea..d66e22139 100644 --- a/ext/php_driver_types.h +++ b/ext/php_driver_types.h @@ -38,7 +38,6 @@ #if PHP_MAJOR_VERSION >= 7 #define PHP_DRIVER_GET_NUMERIC(obj) php_driver_numeric_object_fetch(Z_OBJ_P(obj)) - #define PHP_DRIVER_GET_BLOB(obj) php_driver_blob_object_fetch(Z_OBJ_P(obj)) #define PHP_DRIVER_GET_TIMESTAMP(obj) php_driver_timestamp_object_fetch(Z_OBJ_P(obj)) #define PHP_DRIVER_GET_DATE(obj) php_driver_date_object_fetch(Z_OBJ_P(obj)) #define PHP_DRIVER_GET_TIME(obj) php_driver_time_object_fetch(Z_OBJ_P(obj)) @@ -76,7 +75,6 @@ #define PHP_DRIVER_GET_DURATION(obj) php_driver_duration_object_fetch(Z_OBJ_P(obj)) #else #define PHP_DRIVER_GET_NUMERIC(obj) ((php_driver_numeric *)zend_object_store_get_object((obj) TSRMLS_CC)) - #define PHP_DRIVER_GET_BLOB(obj) ((php_driver_blob *)zend_object_store_get_object((obj) TSRMLS_CC)) #define PHP_DRIVER_GET_TIMESTAMP(obj) ((php_driver_timestamp *)zend_object_store_get_object((obj) TSRMLS_CC)) #define PHP_DRIVER_GET_DATE(obj) ((php_driver_date *)zend_object_store_get_object((obj) TSRMLS_CC)) #define PHP_DRIVER_GET_TIME(obj) ((php_driver_time *)zend_object_store_get_object((obj) TSRMLS_CC)) @@ -160,11 +158,6 @@ PHP_DRIVER_BEGIN_OBJECT_TYPE(time) cass_int64_t time; PHP_DRIVER_END_OBJECT_TYPE(time) -PHP_DRIVER_BEGIN_OBJECT_TYPE(blob) - cass_byte_t *data; - size_t size; -PHP_DRIVER_END_OBJECT_TYPE(blob) - PHP_DRIVER_BEGIN_OBJECT_TYPE(uuid) CassUuid uuid; PHP_DRIVER_END_OBJECT_TYPE(uuid) @@ -517,7 +510,6 @@ extern PHP_DRIVER_API zend_class_entry *php_driver_numeric_ce; extern PHP_DRIVER_API zend_class_entry *php_driver_bigint_ce; extern PHP_DRIVER_API zend_class_entry *php_driver_smallint_ce; extern PHP_DRIVER_API zend_class_entry *php_driver_tinyint_ce; -extern PHP_DRIVER_API zend_class_entry *php_driver_blob_ce; extern PHP_DRIVER_API zend_class_entry *php_driver_decimal_ce; extern PHP_DRIVER_API zend_class_entry *php_driver_float_ce; extern PHP_DRIVER_API zend_class_entry *php_driver_inet_ce; @@ -570,7 +562,6 @@ void php_driver_define_Numeric(TSRMLS_D); void php_driver_define_Bigint(TSRMLS_D); void php_driver_define_Smallint(TSRMLS_D); void php_driver_define_Tinyint(TSRMLS_D); -void php_driver_define_Blob(TSRMLS_D); void php_driver_define_Collection(TSRMLS_D); void php_driver_define_Decimal(TSRMLS_D); void php_driver_define_Float(TSRMLS_D); diff --git a/ext/src/Blob.c b/ext/src/Blob.c deleted file mode 100644 index 17a24300d..000000000 --- a/ext/src/Blob.c +++ /dev/null @@ -1,214 +0,0 @@ -/** - * Copyright 2015-2017 DataStax, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "php_driver.h" -#include "php_driver_types.h" -#include "util/bytes.h" -#include "util/types.h" - -zend_class_entry *php_driver_blob_ce = NULL; - -void -php_driver_blob_init(INTERNAL_FUNCTION_PARAMETERS) -{ - php_driver_blob *self; - char *string; - php5to7_size string_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &string_len) == FAILURE) { - return; - } - - if (getThis() && instanceof_function(Z_OBJCE_P(getThis()), php_driver_blob_ce TSRMLS_CC)) { - self = PHP_DRIVER_GET_BLOB(getThis()); - } else { - object_init_ex(return_value, php_driver_blob_ce); - self = PHP_DRIVER_GET_BLOB(return_value); - } - - self->data = emalloc(string_len * sizeof(cass_byte_t)); - self->size = string_len; - memcpy(self->data, string, string_len); -} - -/* {{{ Blob::__construct(string) */ -PHP_METHOD(Blob, __construct) -{ - php_driver_blob_init(INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ Blob::__toString() */ -PHP_METHOD(Blob, __toString) -{ - php_driver_blob *self = PHP_DRIVER_GET_BLOB(getThis()); - char *hex; - int hex_len; - php_driver_bytes_to_hex((const char *) self->data, self->size, &hex, &hex_len); - - PHP5TO7_RETVAL_STRINGL(hex, hex_len); - efree(hex); -} -/* }}} */ - -/* {{{ Blob::type() */ -PHP_METHOD(Blob, type) -{ - php5to7_zval type = php_driver_type_scalar(CASS_VALUE_TYPE_BLOB TSRMLS_CC); - RETURN_ZVAL(PHP5TO7_ZVAL_MAYBE_P(type), 1, 1); -} -/* }}} */ - -/* {{{ Blob::bytes() */ -PHP_METHOD(Blob, bytes) -{ - php_driver_blob *self = PHP_DRIVER_GET_BLOB(getThis()); - char *hex; - int hex_len; - php_driver_bytes_to_hex((const char *) self->data, self->size, &hex, &hex_len); - - PHP5TO7_RETVAL_STRINGL(hex, hex_len); - efree(hex); -} -/* }}} */ - -/* {{{ Blob::toBinaryString() */ -PHP_METHOD(Blob, toBinaryString) -{ - php_driver_blob *blob = PHP_DRIVER_GET_BLOB(getThis()); - - PHP5TO7_RETVAL_STRINGL((const char *)blob->data, blob->size); -} -/* }}} */ - -ZEND_BEGIN_ARG_INFO_EX(arginfo__construct, 0, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, bytes) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_none, 0, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() - -static zend_function_entry php_driver_blob_methods[] = { - PHP_ME(Blob, __construct, arginfo__construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC) - PHP_ME(Blob, __toString, arginfo_none, ZEND_ACC_PUBLIC) - PHP_ME(Blob, type, arginfo_none, ZEND_ACC_PUBLIC) - PHP_ME(Blob, bytes, arginfo_none, ZEND_ACC_PUBLIC) - PHP_ME(Blob, toBinaryString, arginfo_none, ZEND_ACC_PUBLIC) - PHP_FE_END -}; - -static php_driver_value_handlers php_driver_blob_handlers; - -static HashTable * -php_driver_blob_gc(zval *object, php5to7_zval_gc table, int *n TSRMLS_DC) -{ - *table = NULL; - *n = 0; - return zend_std_get_properties(object TSRMLS_CC); -} - -static HashTable * -php_driver_blob_properties(zval *object TSRMLS_DC) -{ - char *hex; - int hex_len; - php5to7_zval type; - php5to7_zval bytes; - - php_driver_blob *self = PHP_DRIVER_GET_BLOB(object); - HashTable *props = zend_std_get_properties(object TSRMLS_CC); - - type = php_driver_type_scalar(CASS_VALUE_TYPE_BLOB TSRMLS_CC); - PHP5TO7_ZEND_HASH_UPDATE(props, "type", sizeof("type"), PHP5TO7_ZVAL_MAYBE_P(type), sizeof(zval)); - - php_driver_bytes_to_hex((const char *) self->data, self->size, &hex, &hex_len); - PHP5TO7_ZVAL_MAYBE_MAKE(bytes); - PHP5TO7_ZVAL_STRINGL(PHP5TO7_ZVAL_MAYBE_P(bytes), hex, hex_len); - efree(hex); - PHP5TO7_ZEND_HASH_UPDATE(props, "bytes", sizeof("bytes"), PHP5TO7_ZVAL_MAYBE_P(bytes), sizeof(zval)); - - return props; -} - -static int -php_driver_blob_compare(zval *obj1, zval *obj2 TSRMLS_DC) -{ - php_driver_blob *blob1 = NULL; - php_driver_blob *blob2 = NULL; - - if (Z_OBJCE_P(obj1) != Z_OBJCE_P(obj2)) - return 1; /* different classes */ - - blob1 = PHP_DRIVER_GET_BLOB(obj1); - blob2 = PHP_DRIVER_GET_BLOB(obj2); - - if (blob1->size == blob2->size) { - return memcmp((const char *) blob1->data, (const char *) blob2->data, blob1->size); - } else if (blob1->size < blob2->size) { - return -1; - } else { - return 1; - } -} - -static unsigned -php_driver_blob_hash_value(zval *obj TSRMLS_DC) -{ - php_driver_blob *self = PHP_DRIVER_GET_BLOB(obj); - return zend_inline_hash_func((const char *) self->data, self->size); -} - -static void -php_driver_blob_free(php5to7_zend_object_free *object TSRMLS_DC) -{ - php_driver_blob *self = PHP5TO7_ZEND_OBJECT_GET(blob, object); - - if (self->data) { - efree(self->data); - } - - zend_object_std_dtor(&self->zval TSRMLS_CC); - PHP5TO7_MAYBE_EFREE(self); -} - -static php5to7_zend_object -php_driver_blob_new(zend_class_entry *ce TSRMLS_DC) -{ - php_driver_blob *self = - PHP5TO7_ZEND_OBJECT_ECALLOC(blob, ce); - - PHP5TO7_ZEND_OBJECT_INIT(blob, self, ce); -} - -void php_driver_define_Blob(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, PHP_DRIVER_NAMESPACE "\\Blob", php_driver_blob_methods); - php_driver_blob_ce = zend_register_internal_class(&ce TSRMLS_CC); - zend_class_implements(php_driver_blob_ce TSRMLS_CC, 1, php_driver_value_ce); - memcpy(&php_driver_blob_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_driver_blob_handlers.std.get_properties = php_driver_blob_properties; -#if PHP_VERSION_ID >= 50400 - php_driver_blob_handlers.std.get_gc = php_driver_blob_gc; -#endif - php_driver_blob_handlers.std.compare_objects = php_driver_blob_compare; - php_driver_blob_ce->ce_flags |= PHP5TO7_ZEND_ACC_FINAL; - php_driver_blob_ce->create_object = php_driver_blob_new; - - php_driver_blob_handlers.hash_value = php_driver_blob_hash_value; - php_driver_blob_handlers.std.clone_obj = NULL; -} diff --git a/ext/src/Blob.h b/ext/src/Blob.h deleted file mode 100644 index 73de45fd1..000000000 --- a/ext/src/Blob.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright 2015-2017 DataStax, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PHP_DRIVER_BLOB_H -#define PHP_DRIVER_BLOB_H - -void php_driver_blob_init(INTERNAL_FUNCTION_PARAMETERS); - -#endif /* PHP_DRIVER_BLOB_H */ diff --git a/ext/src/Blob.yaml b/ext/src/Blob.yaml deleted file mode 100644 index 307d99d18..000000000 --- a/ext/src/Blob.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -Blob: - comment: A PHP representation of the CQL `blob` datatype - methods: - __construct: - comment: Creates a new bytes array. - params: - bytes: - comment: any bytes - type: string - type: - comment: The type of this blob. - return: - comment: "" - type: \Cassandra\Type - bytes: - comment: Returns bytes as a hex string. - return: - comment: bytes as hexadecimal string - type: string - __toString: - comment: Returns bytes as a hex string. - return: - comment: bytes as hexadecimal string - type: string - toBinaryString: - comment: Returns bytes as a binary string. - return: - comment: bytes as binary string - type: string -... diff --git a/ext/src/DefaultSession.c b/ext/src/DefaultSession.c index 4fea3fbd4..83b0e5c5d 100644 --- a/ext/src/DefaultSession.c +++ b/ext/src/DefaultSession.c @@ -57,7 +57,7 @@ bind_argument_by_index(CassStatement *statement, size_t index, zval *value TSRML CHECK_RESULT(cass_statement_bind_null(statement, index)); if (Z_TYPE_P(value) == IS_STRING) - CHECK_RESULT(cass_statement_bind_string(statement, index, Z_STRVAL_P(value))); + CHECK_RESULT(cass_statement_bind_bytes(statement, index, Z_STRVAL_P(value), Z_STRLEN_P(value))); if (Z_TYPE_P(value) == IS_DOUBLE) CHECK_RESULT(cass_statement_bind_double(statement, index, Z_DVAL_P(value))); @@ -107,11 +107,6 @@ bind_argument_by_index(CassStatement *statement, size_t index, zval *value TSRML CHECK_RESULT(cass_statement_bind_int64(statement, index, time->time)); } - if (instanceof_function(Z_OBJCE_P(value), php_driver_blob_ce TSRMLS_CC)) { - php_driver_blob *blob = PHP_DRIVER_GET_BLOB(value); - CHECK_RESULT(cass_statement_bind_bytes(statement, index, blob->data, blob->size)); - } - if (instanceof_function(Z_OBJCE_P(value), php_driver_varint_ce TSRMLS_CC)) { php_driver_numeric *varint = PHP_DRIVER_GET_NUMERIC(value); size_t size; @@ -220,7 +215,7 @@ bind_argument_by_name(CassStatement *statement, const char *name, } if (Z_TYPE_P(value) == IS_STRING) - CHECK_RESULT(cass_statement_bind_string_by_name(statement, name, Z_STRVAL_P(value))); + CHECK_RESULT(cass_statement_bind_bytes_by_name(statement, name, Z_STRVAL_P(value), Z_STRLEN_P(value))); if (Z_TYPE_P(value) == IS_DOUBLE) CHECK_RESULT(cass_statement_bind_double_by_name(statement, name, Z_DVAL_P(value))); @@ -270,11 +265,6 @@ bind_argument_by_name(CassStatement *statement, const char *name, CHECK_RESULT(cass_statement_bind_int64_by_name(statement, name, time->time)); } - if (instanceof_function(Z_OBJCE_P(value), php_driver_blob_ce TSRMLS_CC)) { - php_driver_blob *blob = PHP_DRIVER_GET_BLOB(value); - CHECK_RESULT(cass_statement_bind_bytes_by_name(statement, name, blob->data, blob->size)); - } - if (instanceof_function(Z_OBJCE_P(value), php_driver_varint_ce TSRMLS_CC)) { php_driver_numeric *varint = PHP_DRIVER_GET_NUMERIC(value); size_t size; diff --git a/ext/util/collections.c b/ext/util/collections.c index 0b88186d4..8b955e1e8 100644 --- a/ext/util/collections.c +++ b/ext/util/collections.c @@ -49,6 +49,7 @@ php_driver_validate_object(zval *object, zval *ztype TSRMLS_DC) case CASS_VALUE_TYPE_VARCHAR: case CASS_VALUE_TYPE_TEXT: case CASS_VALUE_TYPE_ASCII: + case CASS_VALUE_TYPE_BLOB: if (Z_TYPE_P(object) != IS_STRING) { EXPECTING_VALUE("a string"); } @@ -96,12 +97,6 @@ php_driver_validate_object(zval *object, zval *ztype TSRMLS_DC) EXPECTING_VALUE("an instance of " PHP_DRIVER_NAMESPACE "\\Tinyint"); } - return 1; - case CASS_VALUE_TYPE_BLOB: - if (!INSTANCE_OF(php_driver_blob_ce)) { - EXPECTING_VALUE("an instance of " PHP_DRIVER_NAMESPACE "\\Blob"); - } - return 1; case CASS_VALUE_TYPE_DECIMAL: if (!INSTANCE_OF(php_driver_decimal_ce)) { @@ -282,7 +277,6 @@ static int php_driver_collection_append(CassCollection *collection, zval *value, CassValueType type TSRMLS_DC) { int result = 1; - php_driver_blob *blob; php_driver_numeric *numeric; php_driver_timestamp *timestamp; php_driver_date *date; @@ -321,8 +315,7 @@ php_driver_collection_append(CassCollection *collection, zval *value, CassValueT CHECK_ERROR(cass_collection_append_int8(collection, numeric->data.tinyint.value)); break; case CASS_VALUE_TYPE_BLOB: - blob = PHP_DRIVER_GET_BLOB(value); - CHECK_ERROR(cass_collection_append_bytes(collection, blob->data, blob->size)); + CHECK_ERROR(cass_collection_append_bytes(collection, Z_STRVAL_P(value), Z_STRLEN_P(value))); break; case CASS_VALUE_TYPE_BOOLEAN: #if PHP_MAJOR_VERSION >= 7 @@ -420,7 +413,6 @@ static int php_driver_tuple_set(CassTuple *tuple, php5to7_ulong index, zval *value, CassValueType type TSRMLS_DC) { int result = 1; - php_driver_blob *blob; php_driver_numeric *numeric; php_driver_timestamp *timestamp; php_driver_date *date; @@ -464,8 +456,7 @@ php_driver_tuple_set(CassTuple *tuple, php5to7_ulong index, zval *value, CassVal CHECK_ERROR(cass_tuple_set_int8(tuple, index, numeric->data.tinyint.value)); break; case CASS_VALUE_TYPE_BLOB: - blob = PHP_DRIVER_GET_BLOB(value); - CHECK_ERROR(cass_tuple_set_bytes(tuple, index, blob->data, blob->size)); + CHECK_ERROR(cass_tuple_set_bytes(tuple, index, Z_STRVAL_P(value), Z_STRLEN_P(value))); break; case CASS_VALUE_TYPE_BOOLEAN: #if PHP_MAJOR_VERSION >= 7 @@ -565,7 +556,6 @@ php_driver_user_type_set(CassUserType *ut, CassValueType type TSRMLS_DC) { int result = 1; - php_driver_blob *blob; php_driver_numeric *numeric; php_driver_timestamp *timestamp; php_driver_date *date; @@ -593,7 +583,7 @@ php_driver_user_type_set(CassUserType *ut, case CASS_VALUE_TYPE_TEXT: case CASS_VALUE_TYPE_ASCII: case CASS_VALUE_TYPE_VARCHAR: - CHECK_ERROR(cass_user_type_set_string_by_name(ut, name, Z_STRVAL_P(value))); + CHECK_ERROR(cass_user_type_set_string_by_name_n(ut, name, strlen(name) + 1, Z_STRVAL_P(value), Z_STRLEN_P(value))); break; case CASS_VALUE_TYPE_BIGINT: case CASS_VALUE_TYPE_COUNTER: @@ -609,8 +599,7 @@ php_driver_user_type_set(CassUserType *ut, CHECK_ERROR(cass_user_type_set_int8_by_name(ut, name, numeric->data.tinyint.value)); break; case CASS_VALUE_TYPE_BLOB: - blob = PHP_DRIVER_GET_BLOB(value); - CHECK_ERROR(cass_user_type_set_bytes_by_name(ut, name, blob->data, blob->size)); + CHECK_ERROR(cass_user_type_set_bytes_by_name(ut, name, Z_STRVAL_P(value), Z_STRLEN_P(value))); break; case CASS_VALUE_TYPE_BOOLEAN: #if PHP_MAJOR_VERSION >= 7 diff --git a/ext/util/result.c b/ext/util/result.c index 2a0b6e744..0f76c1797 100644 --- a/ext/util/result.c +++ b/ext/util/result.c @@ -45,7 +45,6 @@ php_driver_value(const CassValue* value, const CassDataType* data_type, php5to7_ php_driver_timestamp *timestamp = NULL; php_driver_date *date = NULL; php_driver_time *time = NULL; - php_driver_blob *blob = NULL; php_driver_inet *inet = NULL; php_driver_duration *duration = NULL; php_driver_collection *collection = NULL; @@ -70,6 +69,7 @@ php_driver_value(const CassValue* value, const CassDataType* data_type, php5to7_ case CASS_VALUE_TYPE_ASCII: case CASS_VALUE_TYPE_TEXT: case CASS_VALUE_TYPE_VARCHAR: + case CASS_VALUE_TYPE_BLOB: ASSERT_SUCCESS_BLOCK(cass_value_get_string(value, &v_string, &v_string_len), zval_ptr_dtor(out); return FAILURE; @@ -132,17 +132,6 @@ php_driver_value(const CassValue* value, const CassDataType* data_type, php5to7_ return FAILURE; ) break; - case CASS_VALUE_TYPE_BLOB: - object_init_ex(PHP5TO7_ZVAL_MAYBE_DEREF(out), php_driver_blob_ce); - blob = PHP_DRIVER_GET_BLOB(PHP5TO7_ZVAL_MAYBE_DEREF(out)); - ASSERT_SUCCESS_BLOCK(cass_value_get_bytes(value, &v_bytes, &v_bytes_len), - zval_ptr_dtor(out); - return FAILURE; - ) - blob->data = emalloc(v_bytes_len * sizeof(cass_byte_t)); - blob->size = v_bytes_len; - memcpy(blob->data, v_bytes, v_bytes_len); - break; case CASS_VALUE_TYPE_VARINT: object_init_ex(PHP5TO7_ZVAL_MAYBE_DEREF(out), php_driver_varint_ce); numeric = PHP_DRIVER_GET_NUMERIC(PHP5TO7_ZVAL_MAYBE_DEREF(out)); diff --git a/ext/util/types.c b/ext/util/types.c index bef2fa290..66f64e344 100644 --- a/ext/util/types.c +++ b/ext/util/types.c @@ -26,7 +26,6 @@ #include "src/Bigint.h" #include "src/Smallint.h" #include "src/Tinyint.h" -#include "src/Blob.h" #include "src/Decimal.h" #include "src/Duration.h" #include "src/Float.h" @@ -568,6 +567,12 @@ php_driver_ascii_init(INTERNAL_FUNCTION_PARAMETERS) php_driver_varchar_init(INTERNAL_FUNCTION_PARAM_PASSTHRU); } +static void +php_driver_blob_init(INTERNAL_FUNCTION_PARAMETERS) +{ + php_driver_varchar_init(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} + static void php_driver_boolean_init(INTERNAL_FUNCTION_PARAMETERS) { diff --git a/tests/integration/Cassandra/DatatypeIntegrationTests.php b/tests/integration/Cassandra/DatatypeIntegrationTests.php index 4e64ed7e1..0e525d2c7 100644 --- a/tests/integration/Cassandra/DatatypeIntegrationTests.php +++ b/tests/integration/Cassandra/DatatypeIntegrationTests.php @@ -29,7 +29,7 @@ public function scalarCassandraTypes() { return array( array(Type::ascii(), array("a", "b", "c")), array(Type::bigint(), array(new Bigint("1"), new Bigint("2"), new Bigint("3"))), - array(Type::blob(), array(new Blob("x"), new Blob("y"), new Blob("z"))), + array(Type::blob(), array("a", "b", "c")), array(Type::boolean(), array(true, false, true, false)), array(Type::date(), array(new Date(), new Date(0), new Date(-86400), new Date(86400))), array(Type::decimal(), array(new Decimal(1.1), new Decimal(2.2), new Decimal(3.3))), diff --git a/tests/unit/Cassandra/BlobTest.php b/tests/unit/Cassandra/BlobTest.php deleted file mode 100644 index d0e5e6659..000000000 --- a/tests/unit/Cassandra/BlobTest.php +++ /dev/null @@ -1,70 +0,0 @@ -assertEquals("0x4869", $blob->__toString()); - $this->assertEquals("0x4869", $blob->bytes()); - } - - public function testReturnsOriginalBytesAsBinaryString() - { - $blob = new Blob("Hi"); - $this->assertEquals("Hi", (string) $blob->toBinaryString()); - } - - /** - * @dataProvider equalTypes - */ - public function testCompareEquals($value1, $value2) - { - $this->assertEquals($value1, $value2); - $this->assertTrue($value1 == $value2); - } - - public function equalTypes() - { - return array( - array(new Blob("0x1234"), new Blob("0x1234")), - ); - } - - /** - * @dataProvider notEqualTypes - */ - public function testCompareNotEquals($value1, $value2) - { - $this->assertNotEquals($value1, $value2); - $this->assertFalse($value1 == $value2); - } - - public function notEqualTypes() - { - return array( - array(new Blob("0x1234"), new Blob("0x4567")), - ); - } -} diff --git a/tests/unit/Cassandra/CollectionTest.php b/tests/unit/Cassandra/CollectionTest.php index b3e85d9ef..86395463b 100644 --- a/tests/unit/Cassandra/CollectionTest.php +++ b/tests/unit/Cassandra/CollectionTest.php @@ -99,7 +99,7 @@ public function scalarTypes() return array( array(Type::ascii(), "ascii"), array(Type::bigint(), new Bigint("9223372036854775807")), - array(Type::blob(), new Blob("blob")), + array(Type::blob(), "blob"), array(Type::boolean(), true), array(Type::counter(), new Bigint(123)), array(Type::decimal(), new Decimal("3.14159265359")), diff --git a/tests/unit/Cassandra/MapTest.php b/tests/unit/Cassandra/MapTest.php index 8b88c31ae..c98501c9a 100644 --- a/tests/unit/Cassandra/MapTest.php +++ b/tests/unit/Cassandra/MapTest.php @@ -121,7 +121,7 @@ public function scalarTypes() return array( array(Type::ascii(), array("ascii")), array(Type::bigint(), array(new Bigint("9223372036854775807"))), - array(Type::blob(), array(new Blob("blob"))), + array(Type::blob(), array("blob")), array(Type::boolean(), array(true, false)), array(Type::counter(), array(new Bigint(123))), array(Type::decimal(), array(new Decimal("3.14159265359"))), diff --git a/tests/unit/Cassandra/SetTest.php b/tests/unit/Cassandra/SetTest.php index 2da3cc88b..222dfe9b8 100644 --- a/tests/unit/Cassandra/SetTest.php +++ b/tests/unit/Cassandra/SetTest.php @@ -87,7 +87,7 @@ public function scalarTypes() return array( array(Type::ascii(), array("ascii")), array(Type::bigint(), array(new Bigint("9223372036854775807"))), - array(Type::blob(), array(new Blob("blob"))), + array(Type::blob(), array("blob")), array(Type::boolean(), array(true, false)), array(Type::counter(), array(new Bigint(123))), array(Type::decimal(), array(new Decimal("3.14159265359"))), diff --git a/tests/unit/Cassandra/TupleTest.php b/tests/unit/Cassandra/TupleTest.php index 34e420ca4..f52c8ad1d 100644 --- a/tests/unit/Cassandra/TupleTest.php +++ b/tests/unit/Cassandra/TupleTest.php @@ -91,7 +91,7 @@ public function scalarTypes() return array( array(Type::ascii(), "ascii"), array(Type::bigint(), new Bigint("9223372036854775807")), - array(Type::blob(), new Blob("blob")), + array(Type::blob(), "blob"), array(Type::boolean(), true), array(Type::counter(), new Bigint(123)), array(Type::decimal(), new Decimal("3.14159265359")), diff --git a/tests/unit/Cassandra/UserTypeValueTest.php b/tests/unit/Cassandra/UserTypeValueTest.php index 8c0b27756..bd23f56ec 100644 --- a/tests/unit/Cassandra/UserTypeValueTest.php +++ b/tests/unit/Cassandra/UserTypeValueTest.php @@ -88,7 +88,7 @@ public function scalarTypes() return array( array(Type::ascii(), "ascii", "ascii"), array(Type::bigint(), new Bigint("9223372036854775807"), new Bigint("9223372036854775807")), - array(Type::blob(), new Blob("blob"), new Blob("blob")), + array(Type::blob(), "blob", "blob"), array(Type::boolean(), true, true), array(Type::counter(), new Bigint(123), new Bigint(123)), array(Type::decimal(), new Decimal("3.14159265359"), new Decimal("3.14159265359")),