Skip to content

Commit 4da3b23

Browse files
committed
PHP 8 Compatibility with PreparedStatements
1 parent 824ba30 commit 4da3b23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1218
-152
lines changed

ext/php_driver.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,25 @@ PHP_MINFO_FUNCTION(php_driver)
598598
{
599599
char buf[256];
600600
php_info_print_table_start();
601-
php_info_print_table_header(2, PHP_DRIVER_NAMESPACE " support", "enabled");
601+
602+
php_info_print_table_row(2, PHP_DRIVER_NAMESPACE " support", "enabled");
602603

603604
snprintf(buf, sizeof(buf), "%d.%d.%d%s",
604605
CASS_VERSION_MAJOR, CASS_VERSION_MINOR, CASS_VERSION_PATCH,
605-
strlen(CASS_VERSION_SUFFIX) > 0 ? "-" CASS_VERSION_SUFFIX : "");
606+
(strlen(CASS_VERSION_SUFFIX) > 0 ? "-" CASS_VERSION_SUFFIX : ""));
606607
php_info_print_table_row(2, "C/C++ driver version", buf);
607608

609+
php_info_print_table_row(2, "PHP driver extension", "customized for persistent prepared statements");
610+
608611
snprintf(buf, sizeof(buf), "%d", PHP_DRIVER_G(persistent_clusters));
609612
php_info_print_table_row(2, "Persistent Clusters", buf);
610613

611614
snprintf(buf, sizeof(buf), "%d", PHP_DRIVER_G(persistent_sessions));
612615
php_info_print_table_row(2, "Persistent Sessions", buf);
613616

617+
snprintf(buf, sizeof(buf), "%d", PHP_DRIVER_G(persistent_prepared_statements));
618+
php_info_print_table_row(2, "Persistent Prepared Statements", buf);
619+
614620
php_info_print_table_end();
615621

616622
DISPLAY_INI_ENTRIES();

ext/php_driver.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ typedef int pid_t;
4646
# error PHP 5.6.0 or later is required in order to build the driver
4747
#endif
4848

49+
#if PHP_VERSION_ID >= 80000
50+
#ifndef TSRMLS_D
51+
#define TSRMLS_D void
52+
#define TSRMLS_DC
53+
#define TSRMLS_C
54+
#define TSRMLS_CC
55+
#define TSRMLS_FETCH()
56+
#endif
57+
#endif
58+
4959
#include <ext/spl/spl_iterators.h>
5060
#include <ext/spl/spl_exceptions.h>
5161

ext/php_driver_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_driver)
66
pid_t uuid_gen_pid;
77
unsigned int persistent_clusters;
88
unsigned int persistent_sessions;
9+
unsigned int persistent_prepared_statements;
910
php5to7_zval type_varchar;
1011
php5to7_zval type_text;
1112
php5to7_zval type_blob;
@@ -27,6 +28,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_driver)
2728
php5to7_zval type_smallint;
2829
php5to7_zval type_tinyint;
2930
php5to7_zval type_duration;
31+
zend_resource stmt;
3032
ZEND_END_MODULE_GLOBALS(php_driver)
3133

3234
ZEND_EXTERN_MODULE_GLOBALS(php_driver)

ext/php_driver_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,26 @@ PHP_DRIVER_BEGIN_OBJECT_TYPE(future_session)
367367
int hash_key_len;
368368
char *exception_message;
369369
CassError exception_code;
370+
char* session_keyspace;
371+
char* session_hash_key;
370372
PHP_DRIVER_END_OBJECT_TYPE(future_session)
371373

372374
typedef struct {
373375
CassFuture *future;
374376
php_driver_ref *session;
375377
} php_driver_psession;
376378

379+
typedef struct {
380+
CassFuture *future;
381+
php_driver_ref *ref;
382+
} php_driver_pprepared_statement;
383+
377384
PHP_DRIVER_BEGIN_OBJECT_TYPE(session)
378385
php_driver_ref *session;
379386
long default_consistency;
380387
int default_page_size;
388+
char* keyspace;
389+
char* hash_key;
381390
php5to7_zval default_timeout;
382391
cass_bool_t persist;
383392
PHP_DRIVER_END_OBJECT_TYPE(session)
@@ -734,5 +743,6 @@ void php_driver_define_TimestampGeneratorServerSide(TSRMLS_D);
734743

735744
extern int php_le_php_driver_cluster();
736745
extern int php_le_php_driver_session();
746+
extern int php_le_php_driver_prepared_statement();
737747

738748
#endif /* PHP_DRIVER_TYPES_H */

ext/src/BatchStatement.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,15 @@ static zend_function_entry php_driver_batch_statement_methods[] = {
122122

123123
static zend_object_handlers php_driver_batch_statement_handlers;
124124

125+
125126
static HashTable *
126-
php_driver_batch_statement_properties(zval *object TSRMLS_DC)
127+
php_driver_batch_statement_properties(
128+
#if PHP_VERSION_ID >= 80000
129+
zend_object *object TSRMLS_DC
130+
#else
131+
zval *object TSRMLS_DC
132+
#endif
133+
)
127134
{
128135
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
129136

@@ -175,6 +182,14 @@ void php_driver_define_BatchStatement(TSRMLS_D)
175182

176183
memcpy(&php_driver_batch_statement_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
177184
php_driver_batch_statement_handlers.get_properties = php_driver_batch_statement_properties;
185+
#if PHP_VERSION_ID >= 80000
186+
php_driver_batch_statement_handlers.compare = php_driver_batch_statement_compare;
187+
#else
188+
#if PHP_VERSION_ID >= 80000
189+
php_driver_batch_statement_handlers.compare = php_driver_batch_statement_compare;
190+
#else
178191
php_driver_batch_statement_handlers.compare_objects = php_driver_batch_statement_compare;
192+
#endif
193+
#endif
179194
php_driver_batch_statement_handlers.clone_obj = NULL;
180195
}

ext/src/Bigint.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,38 @@ static zend_function_entry php_driver_bigint_methods[] = {
394394
static php_driver_value_handlers php_driver_bigint_handlers;
395395

396396
static HashTable *
397-
php_driver_bigint_gc(zval *object, php5to7_zval_gc table, int *n TSRMLS_DC)
397+
php_driver_bigint_gc(
398+
#if PHP_VERSION_ID >= 80000
399+
zend_object *object,
400+
#else
401+
zval *object,
402+
#endif
403+
php5to7_zval_gc table, int *n TSRMLS_DC)
398404
{
399405
*table = NULL;
400406
*n = 0;
401407
return zend_std_get_properties(object TSRMLS_CC);
402408
}
403409

404410
static HashTable *
405-
php_driver_bigint_properties(zval *object TSRMLS_DC)
411+
php_driver_bigint_properties(
412+
#if PHP_VERSION_ID >= 80000
413+
zend_object *object TSRMLS_DC
414+
#else
415+
zval *object TSRMLS_DC
416+
#endif
417+
)
406418
{
407419
php5to7_zval type;
408420
php5to7_zval value;
409421

410-
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(object);
422+
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(
423+
#if PHP_VERSION_ID >= 80000
424+
(zval*) object
425+
#else
426+
object
427+
#endif
428+
);
411429
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
412430

413431
type = php_driver_type_scalar(CASS_VALUE_TYPE_BIGINT TSRMLS_CC);
@@ -448,9 +466,21 @@ php_driver_bigint_hash_value(zval *obj TSRMLS_DC)
448466
}
449467

450468
static int
451-
php_driver_bigint_cast(zval *object, zval *retval, int type TSRMLS_DC)
469+
php_driver_bigint_cast(
470+
#if PHP_VERSION_ID >= 80000
471+
zend_object *object,
472+
#else
473+
zval *object,
474+
#endif
475+
zval *retval, int type TSRMLS_DC)
452476
{
453-
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(object);
477+
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(
478+
#if PHP_VERSION_ID >= 80000
479+
(zval*) object
480+
#else
481+
object
482+
#endif
483+
);
454484

455485
switch (type) {
456486
case IS_LONG:
@@ -501,8 +531,8 @@ void php_driver_define_Bigint(TSRMLS_D)
501531
#if PHP_VERSION_ID >= 50400
502532
php_driver_bigint_handlers.std.get_gc = php_driver_bigint_gc;
503533
#endif
504-
php_driver_bigint_handlers.std.compare_objects = php_driver_bigint_compare;
505-
php_driver_bigint_handlers.std.cast_object = php_driver_bigint_cast;
534+
php_driver_bigint_handlers.std.compare = php_driver_bigint_compare;
535+
php_driver_bigint_handlers.std.cast_object = php_driver_bigint_cast;
506536

507537
php_driver_bigint_handlers.hash_value = php_driver_bigint_hash_value;
508538
php_driver_bigint_handlers.std.clone_obj = NULL;

ext/src/Blob.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,40 @@ static zend_function_entry php_driver_blob_methods[] = {
113113
static php_driver_value_handlers php_driver_blob_handlers;
114114

115115
static HashTable *
116-
php_driver_blob_gc(zval *object, php5to7_zval_gc table, int *n TSRMLS_DC)
116+
php_driver_blob_gc(
117+
#if PHP_VERSION_ID >= 80000
118+
zend_object *object,
119+
#else
120+
zval *object,
121+
#endif
122+
php5to7_zval_gc table, int *n TSRMLS_DC)
117123
{
118124
*table = NULL;
119125
*n = 0;
120126
return zend_std_get_properties(object TSRMLS_CC);
121127
}
122128

123129
static HashTable *
124-
php_driver_blob_properties(zval *object TSRMLS_DC)
130+
php_driver_blob_properties(
131+
#if PHP_VERSION_ID >= 80000
132+
zend_object *object TSRMLS_DC
133+
#else
134+
zval *object TSRMLS_DC
135+
#endif
136+
)
125137
{
126138
char *hex;
127139
int hex_len;
128140
php5to7_zval type;
129141
php5to7_zval bytes;
130142

131-
php_driver_blob *self = PHP_DRIVER_GET_BLOB(object);
143+
php_driver_blob *self = PHP_DRIVER_GET_BLOB(
144+
#if PHP_VERSION_ID >= 80000
145+
(zval*) object
146+
#else
147+
object
148+
#endif
149+
);
132150
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
133151

134152
type = php_driver_type_scalar(CASS_VALUE_TYPE_BLOB TSRMLS_CC);
@@ -205,7 +223,15 @@ void php_driver_define_Blob(TSRMLS_D)
205223
#if PHP_VERSION_ID >= 50400
206224
php_driver_blob_handlers.std.get_gc = php_driver_blob_gc;
207225
#endif
226+
#if PHP_VERSION_ID >= 80000
227+
php_driver_blob_handlers.std.compare = php_driver_blob_compare;
228+
#else
229+
#if PHP_VERSION_ID >= 80000
230+
php_driver_blob_handlers.std.compare = php_driver_blob_compare;
231+
#else
208232
php_driver_blob_handlers.std.compare_objects = php_driver_blob_compare;
233+
#endif
234+
#endif
209235
php_driver_blob_ce->ce_flags |= PHP5TO7_ZEND_ACC_FINAL;
210236
php_driver_blob_ce->create_object = php_driver_blob_new;
211237

ext/src/Cluster/Builder.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,15 +1063,28 @@ static zend_function_entry php_driver_cluster_builder_methods[] = {
10631063
static zend_object_handlers php_driver_cluster_builder_handlers;
10641064

10651065
static HashTable*
1066-
php_driver_cluster_builder_gc(zval *object, php5to7_zval_gc table, int *n TSRMLS_DC)
1066+
php_driver_cluster_builder_gc(
1067+
#if PHP_VERSION_ID >= 80000
1068+
zend_object *object,
1069+
#else
1070+
zval *object,
1071+
#endif
1072+
php5to7_zval_gc table, int *n TSRMLS_DC
1073+
)
10671074
{
10681075
*table = NULL;
10691076
*n = 0;
10701077
return zend_std_get_properties(object TSRMLS_CC);
10711078
}
10721079

10731080
static HashTable*
1074-
php_driver_cluster_builder_properties(zval *object TSRMLS_DC)
1081+
php_driver_cluster_builder_properties(
1082+
#if PHP_VERSION_ID >= 80000
1083+
zend_object *object TSRMLS_DC
1084+
#else
1085+
zval *object TSRMLS_DC
1086+
#endif
1087+
)
10751088
{
10761089
php5to7_zval contactPoints;
10771090
php5to7_zval loadBalancingPolicy;
@@ -1107,7 +1120,13 @@ php_driver_cluster_builder_properties(zval *object TSRMLS_DC)
11071120
php5to7_zval randomizedContactPoints;
11081121
php5to7_zval connectionHeartbeatInterval;
11091122

1110-
php_driver_cluster_builder *self = PHP_DRIVER_GET_CLUSTER_BUILDER(object);
1123+
php_driver_cluster_builder *self = PHP_DRIVER_GET_CLUSTER_BUILDER(
1124+
#if PHP_VERSION_ID >= 80000
1125+
(zval*) object
1126+
#else
1127+
object
1128+
#endif
1129+
);
11111130
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
11121131

11131132
PHP5TO7_ZVAL_MAYBE_MAKE(contactPoints);
@@ -1442,5 +1461,13 @@ void php_driver_define_ClusterBuilder(TSRMLS_D)
14421461
#if PHP_VERSION_ID >= 50400
14431462
php_driver_cluster_builder_handlers.get_gc = php_driver_cluster_builder_gc;
14441463
#endif
1464+
#if PHP_VERSION_ID >= 80000
1465+
php_driver_cluster_builder_handlers.compare = php_driver_cluster_builder_compare;
1466+
#else
1467+
#if PHP_VERSION_ID >= 80000
1468+
php_driver_cluster_builder_handlers.compare = php_driver_cluster_builder_compare;
1469+
#else
14451470
php_driver_cluster_builder_handlers.compare_objects = php_driver_cluster_builder_compare;
1471+
#endif
1472+
#endif
14461473
}

ext/src/Collection.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,37 @@ static zend_function_entry php_driver_collection_methods[] = {
312312
static php_driver_value_handlers php_driver_collection_handlers;
313313

314314
static HashTable *
315-
php_driver_collection_gc(zval *object, php5to7_zval_gc table, int *n TSRMLS_DC)
315+
php_driver_collection_gc(
316+
#if PHP_VERSION_ID >= 80000
317+
zend_object *object,
318+
#else
319+
zval *object,
320+
#endif
321+
php5to7_zval_gc table, int *n TSRMLS_DC)
316322
{
317323
*table = NULL;
318324
*n = 0;
319325
return zend_std_get_properties(object TSRMLS_CC);
320326
}
321327

322328
static HashTable *
323-
php_driver_collection_properties(zval *object TSRMLS_DC)
329+
php_driver_collection_properties(
330+
#if PHP_VERSION_ID >= 80000
331+
zend_object *object
332+
#else
333+
zval *object TSRMLS_DC
334+
#endif
335+
)
324336
{
325337
php5to7_zval values;
326338

327-
php_driver_collection *self = PHP_DRIVER_GET_COLLECTION(object);
339+
php_driver_collection *self = PHP_DRIVER_GET_COLLECTION(
340+
#if PHP_VERSION_ID >= 80000
341+
(zval*) object
342+
#else
343+
object
344+
#endif
345+
);
328346
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
329347

330348
PHP5TO7_ZEND_HASH_UPDATE(props,
@@ -442,7 +460,15 @@ void php_driver_define_Collection(TSRMLS_D)
442460
#if PHP_VERSION_ID >= 50400
443461
php_driver_collection_handlers.std.get_gc = php_driver_collection_gc;
444462
#endif
463+
#if PHP_VERSION_ID >= 80000
464+
php_driver_collection_handlers.std.compare = php_driver_collection_compare;
465+
#else
466+
#if PHP_VERSION_ID >= 80000
467+
php_driver_collection_handlers.std.compare = php_driver_collection_compare;
468+
#else
445469
php_driver_collection_handlers.std.compare_objects = php_driver_collection_compare;
470+
#endif
471+
#endif
446472
php_driver_collection_ce->ce_flags |= PHP5TO7_ZEND_ACC_FINAL;
447473
php_driver_collection_ce->create_object = php_driver_collection_new;
448474
zend_class_implements(php_driver_collection_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator);

0 commit comments

Comments
 (0)