Skip to content

Commit 63970ee

Browse files
authored
Merge pull request #118 from datastax/PHP-198
PHP 198 - Merge DSE fixes to core
2 parents 24ef6a5 + 587c83d commit 63970ee

File tree

13 files changed

+161
-73
lines changed

13 files changed

+161
-73
lines changed

ext/src/Cluster/Builder.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ zend_class_entry *php_driver_cluster_builder_ce = NULL;
2929

3030
PHP_METHOD(ClusterBuilder, build)
3131
{
32+
CassError rc;
3233
php_driver_cluster* cluster;
3334
php_driver_cluster_builder *self = PHP_DRIVER_GET_CLUSTER_BUILDER(getThis());
3435

@@ -125,7 +126,16 @@ PHP_METHOD(ClusterBuilder, build)
125126
cass_cluster_set_tcp_nodelay(cluster->cluster, self->enable_tcp_nodelay);
126127
cass_cluster_set_tcp_keepalive(cluster->cluster, self->enable_tcp_keepalive, self->tcp_keepalive_delay);
127128
cass_cluster_set_use_schema(cluster->cluster, self->enable_schema);
128-
ASSERT_SUCCESS(cass_cluster_set_use_hostname_resolution(cluster->cluster, self->enable_hostname_resolution));
129+
130+
rc = cass_cluster_set_use_hostname_resolution(cluster->cluster, self->enable_hostname_resolution);
131+
if (rc == CASS_ERROR_LIB_NOT_IMPLEMENTED) {
132+
if (self->enable_hostname_resolution) {
133+
php_error_docref0(NULL TSRMLS_CC, E_WARNING,
134+
"The underlying C/C++ driver does not implement hostname resolution it will be disabled");
135+
}
136+
} else {
137+
ASSERT_SUCCESS(rc);
138+
}
129139
ASSERT_SUCCESS(cass_cluster_set_use_randomized_contact_points(cluster->cluster, self->enable_randomized_contact_points));
130140
cass_cluster_set_connection_heartbeat_interval(cluster->cluster, self->connection_heartbeat_interval);
131141

ext/src/Cluster/Builder.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ Cluster\Builder:
284284
If enabled the driver will resolve hostnames for IP addresses using
285285
reverse IP lookup. This is useful for authentication (Kerberos) or
286286
encryption SSL services that require a valid hostname for verification.
287+
288+
Important: It's possible that the underlying C/C++ driver does not
289+
support hostname resolution. A PHP warning will be emitted if the driver
290+
does not support hostname resolution.
287291
params:
288292
enabled:
289293
comment: whether the driver uses hostname resolution.

ext/src/Collection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ PHP_METHOD(Collection, __construct)
9797
CassValueType value_type;
9898
if (!php_driver_value_type(Z_STRVAL_P(type), &value_type TSRMLS_CC))
9999
return;
100-
self->type = php_driver_type_set_from_value_type(value_type TSRMLS_CC);
100+
self->type = php_driver_type_collection_from_value_type(value_type TSRMLS_CC);
101101
} else if (Z_TYPE_P(type) == IS_OBJECT &&
102102
instanceof_function(Z_OBJCE_P(type), php_driver_type_ce TSRMLS_CC)) {
103103
if (!php_driver_type_validate(type, "type" TSRMLS_CC)) {

ext/src/Map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ php_driver_map_compare(zval *obj1, zval *obj2 TSRMLS_DC)
524524
return 1;
525525
}
526526
result = php_driver_value_compare(PHP5TO7_ZVAL_MAYBE_P(curr->value),
527-
PHP5TO7_ZVAL_MAYBE_P(entry->value));
527+
PHP5TO7_ZVAL_MAYBE_P(entry->value) TSRMLS_CC);
528528
if (result != 0) return result;
529529
}
530530

ext/src/Timestamp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ PHP_METHOD(Timestamp, toDateTime)
139139
php_date_initialize(datetime_obj, str, str_len, NULL, NULL, 0 TSRMLS_CC);
140140
efree(str);
141141

142-
RETVAL_ZVAL(datetime, 0, 0);
142+
RETVAL_ZVAL(datetime, 0, 1);
143143
}
144144
/* }}} */
145145

ext/src/UserTypeValue.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ PHP_METHOD(UserTypeValue, type)
144144
PHP_METHOD(UserTypeValue, values)
145145
{
146146
php_driver_user_type_value *self = NULL;
147-
array_init(return_value);
148147
self = PHP_DRIVER_GET_USER_TYPE_VALUE(getThis());
149148

150149
array_init(return_value);

ext/util/hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ php_driver_value_hash(zval* zvalue TSRMLS_DC) {
4747

4848
#if PHP_MAJOR_VERSION >= 7
4949
case IS_TRUE: return 1;
50-
case IS_FALSE: return 1;
50+
case IS_FALSE: return 0;
5151
#else
5252
case IS_BOOL: return Z_BVAL_P(zvalue);
5353
#endif

tests/integration/Cassandra/CollectionIntegrationTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,23 @@ public function testScalarTypes($type, $value) {
3838
* Data provider for lists with scalar types
3939
*/
4040
public function collectionWithScalarTypes() {
41-
return array_map(function ($cassandraType) {
42-
$listType = Type::collection($cassandraType[0]);
43-
$list = $listType->create();
44-
foreach ($cassandraType[1] as $value) {
45-
$list->add($value);
46-
}
47-
return array($listType, $list);
48-
}, $this->scalarCassandraTypes());
41+
return array_merge(
42+
array_map(function ($cassandraType) {
43+
$listType = Type::collection($cassandraType[0]);
44+
$list = $listType->create();
45+
foreach ($cassandraType[1] as $value) {
46+
$list->add($value);
47+
}
48+
return array($listType, $list);
49+
}, $this->scalarCassandraTypes()),
50+
array_map(function ($cassandraType) {
51+
$list = new Collection($cassandraType[0]);
52+
foreach ($cassandraType[1] as $value) {
53+
$list->add($value);
54+
}
55+
return array($list->type(), $list);
56+
}, $this->constantScalarCassandraTypes())
57+
);
4958
}
5059

5160
/**

tests/integration/Cassandra/DatatypeIntegrationTests.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function scalarCassandraTypes() {
4040
new Duration(-1, 0, -(2 ** 31)),
4141
new Duration((2 ** 31) - 1, 1, 0),
4242
new Duration(-(2 ** 31), -1, 0))),
43+
array(Type::int(), array(1, 2, 99)),
4344
array(Type::float(), array(new Float(1.0), new Float(2.2), new Float(2.2))),
4445
array(Type::inet(), array(new Inet("127.0.0.1"), new Inet("127.0.0.2"), new Inet("127.0.0.3"))),
4546
array(Type::smallint(), array(Smallint::min(), Smallint::max(), new Smallint(0), new Smallint(74))),
@@ -56,6 +57,40 @@ public function scalarCassandraTypes() {
5657
);
5758
}
5859

60+
/**
61+
* Global constant scalar Cassandra types to be used by data providers
62+
*/
63+
public function constantScalarCassandraTypes() {
64+
$constants = array(
65+
\Cassandra::TYPE_TEXT,
66+
\Cassandra::TYPE_ASCII,
67+
\Cassandra::TYPE_VARCHAR,
68+
\Cassandra::TYPE_BIGINT,
69+
\Cassandra::TYPE_SMALLINT,
70+
\Cassandra::TYPE_TINYINT,
71+
\Cassandra::TYPE_BLOB,
72+
\Cassandra::TYPE_BOOLEAN,
73+
\Cassandra::TYPE_DECIMAL,
74+
\Cassandra::TYPE_DOUBLE,
75+
\Cassandra::TYPE_FLOAT,
76+
\Cassandra::TYPE_INT,
77+
\Cassandra::TYPE_TIMESTAMP,
78+
\Cassandra::TYPE_UUID,
79+
\Cassandra::TYPE_VARINT,
80+
\Cassandra::TYPE_TIMEUUID,
81+
\Cassandra::TYPE_INET
82+
);
83+
$scalarCassandraTypes = $this->scalarCassandraTypes();
84+
85+
return array_map(function($type) use ($scalarCassandraTypes) {
86+
$match = array_filter($scalarCassandraTypes, function($item) use ($type) {
87+
return (string)$item[0] === $type;
88+
});
89+
assert(isset($match) && count($match) > 0);
90+
return array($type, current($match)[1]);
91+
}, $constants);
92+
}
93+
5994
/**
6095
* Create a table using $type for the value's type and insert $value using
6196
* positional parameters.

tests/integration/Cassandra/MapIntegrationTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ function($cassandraType) {
6767
return array($mapType, $map);
6868
}, $this->scalarCassandraTypes());
6969

70-
return array_merge($mapKeyTypes, $mapValueTypes);
70+
$mapConstantScalarTypes = array_map(function ($cassandraType) {
71+
$map = new Map($cassandraType[0], $cassandraType[0]);
72+
$values = $cassandraType[1];
73+
for ($i = 0; $i < count($cassandraType[1]); $i++) {
74+
$map->set($values[$i], $values[$i]);
75+
}
76+
return array($map->type(), $map);
77+
}, $this->constantScalarCassandraTypes());
78+
79+
return array_merge($mapKeyTypes, $mapValueTypes, $mapConstantScalarTypes);
7180
}
7281

7382
/**

0 commit comments

Comments
 (0)