@@ -249,7 +249,11 @@ void swoole_postgresql_init(int module_number) {
249
249
NULL ,
250
250
" Co\\ PostgreSQL" ,
251
251
swoole_postgresql_coro_methods);
252
+ #ifdef SW_SET_CLASS_NOT_SERIALIZABLE
253
+ SW_SET_CLASS_NOT_SERIALIZABLE (swoole_postgresql_coro);
254
+ #else
252
255
SW_SET_CLASS_SERIALIZABLE (swoole_postgresql_coro, zend_class_serialize_deny, zend_class_unserialize_deny);
256
+ #endif
253
257
SW_SET_CLASS_CLONEABLE (swoole_postgresql_coro, sw_zend_class_clone_deny);
254
258
SW_SET_CLASS_UNSET_PROPERTY_HANDLER (swoole_postgresql_coro, sw_zend_class_unset_property_deny);
255
259
SW_SET_CLASS_CUSTOM_OBJECT (swoole_postgresql_coro,
@@ -270,7 +274,7 @@ void swoole_postgresql_init(int module_number) {
270
274
SW_REGISTER_LONG_CONSTANT (" SW_PGSQL_BOTH" , PGSQL_BOTH);
271
275
}
272
276
273
- static char * _php_pgsql_trim_message (const char *message, size_t *len) {
277
+ static char *_php_pgsql_trim_message (const char *message, size_t *len) {
274
278
size_t i = strlen (message);
275
279
if (i > 2 && (message[i - 2 ] == ' \r ' || message[i - 2 ] == ' \n ' ) && message[i - 1 ] == ' .' ) {
276
280
--i;
@@ -291,7 +295,8 @@ static void _php_pgsql_notice_handler(void *resource_id, const char *message) {
291
295
pg_object *object = (pg_object *) resource_id;
292
296
293
297
if (!object->ignore_notices ) {
294
- notices = sw_zend_read_and_convert_property_array (swoole_postgresql_coro_ce, &object->_object , ZEND_STRL (" notices" ), 0 );
298
+ notices = sw_zend_read_and_convert_property_array (
299
+ swoole_postgresql_coro_ce, &object->_object , ZEND_STRL (" notices" ), 0 );
295
300
296
301
trimed_message = _php_pgsql_trim_message (message, &trimed_message_len);
297
302
if (object->log_notices ) {
@@ -443,7 +448,8 @@ static void connect_callback(pg_object *object, Reactor *reactor, Event *event)
443
448
case PGRES_POLLING_FAILED:
444
449
events = 0 ;
445
450
err_msg = PQerrorMessage (conn);
446
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), err_msg);
451
+ zend_update_property_string (
452
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), err_msg);
447
453
break ;
448
454
default :
449
455
swWarn (" PQconnectPoll unexpected status" );
@@ -570,48 +576,44 @@ static int meta_data_result_parse(pg_object *object) {
570
576
}
571
577
572
578
static void set_error_diag (const pg_object *object, const PGresult *pgsql_result) {
573
- const unsigned int error_codes[] = {
574
- PG_DIAG_SEVERITY,
575
- PG_DIAG_SQLSTATE,
576
- PG_DIAG_MESSAGE_PRIMARY,
577
- PG_DIAG_MESSAGE_DETAIL,
578
- PG_DIAG_MESSAGE_HINT,
579
- PG_DIAG_STATEMENT_POSITION,
580
- PG_DIAG_INTERNAL_POSITION,
581
- PG_DIAG_INTERNAL_QUERY,
582
- PG_DIAG_CONTEXT,
583
- PG_DIAG_SCHEMA_NAME,
584
- PG_DIAG_TABLE_NAME,
585
- PG_DIAG_COLUMN_NAME,
586
- PG_DIAG_DATATYPE_NAME,
587
- PG_DIAG_CONSTRAINT_NAME,
588
- PG_DIAG_SOURCE_FILE,
589
- PG_DIAG_SOURCE_LINE,
590
- PG_DIAG_SOURCE_FUNCTION
591
- };
592
-
593
- const char * error_names[] = {
594
- " severity" ,
595
- " sqlstate" ,
596
- " message_primary" ,
597
- " message_detail" ,
598
- " message_hint" ,
599
- " statement_position" ,
600
- " internal_position" ,
601
- " internal_query" ,
602
- " content" ,
603
- " schema_name" ,
604
- " table_name" ,
605
- " column_name" ,
606
- " datatype_name" ,
607
- " constraint_name" ,
608
- " source_file" ,
609
- " source_line" ,
610
- " source_function"
611
- };
579
+ const unsigned int error_codes[] = {PG_DIAG_SEVERITY,
580
+ PG_DIAG_SQLSTATE,
581
+ PG_DIAG_MESSAGE_PRIMARY,
582
+ PG_DIAG_MESSAGE_DETAIL,
583
+ PG_DIAG_MESSAGE_HINT,
584
+ PG_DIAG_STATEMENT_POSITION,
585
+ PG_DIAG_INTERNAL_POSITION,
586
+ PG_DIAG_INTERNAL_QUERY,
587
+ PG_DIAG_CONTEXT,
588
+ PG_DIAG_SCHEMA_NAME,
589
+ PG_DIAG_TABLE_NAME,
590
+ PG_DIAG_COLUMN_NAME,
591
+ PG_DIAG_DATATYPE_NAME,
592
+ PG_DIAG_CONSTRAINT_NAME,
593
+ PG_DIAG_SOURCE_FILE,
594
+ PG_DIAG_SOURCE_LINE,
595
+ PG_DIAG_SOURCE_FUNCTION};
596
+
597
+ const char *error_names[] = {" severity" ,
598
+ " sqlstate" ,
599
+ " message_primary" ,
600
+ " message_detail" ,
601
+ " message_hint" ,
602
+ " statement_position" ,
603
+ " internal_position" ,
604
+ " internal_query" ,
605
+ " content" ,
606
+ " schema_name" ,
607
+ " table_name" ,
608
+ " column_name" ,
609
+ " datatype_name" ,
610
+ " constraint_name" ,
611
+ " source_file" ,
612
+ " source_line" ,
613
+ " source_function" };
612
614
613
615
long unsigned int i;
614
- char * error_result;
616
+ char * error_result;
615
617
616
618
zval result_diag;
617
619
array_init_size (&result_diag, sizeof (error_codes) / sizeof (int ));
@@ -643,10 +645,10 @@ static int query_result_parse(pg_object *object) {
643
645
pgsql_result = PQgetResult (object->conn );
644
646
status = PQresultStatus (pgsql_result);
645
647
646
- zend_update_property_long (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" resultStatus" ), status);
648
+ zend_update_property_long (
649
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" resultStatus" ), status);
647
650
648
- switch (status)
649
- {
651
+ switch (status) {
650
652
case PGRES_EMPTY_QUERY:
651
653
case PGRES_BAD_RESPONSE:
652
654
case PGRES_NONFATAL_ERROR:
@@ -656,7 +658,8 @@ static int query_result_parse(pg_object *object) {
656
658
PQclear (pgsql_result);
657
659
ZVAL_FALSE (&return_value);
658
660
swoole_event_del (object->socket );
659
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), err_msg);
661
+ zend_update_property_string (
662
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), err_msg);
660
663
PHPCoroutine::resume_m (context, &return_value);
661
664
break ;
662
665
case PGRES_COMMAND_OK: /* successful command that did not return rows */
@@ -694,48 +697,52 @@ static int prepare_result_parse(pg_object *object) {
694
697
pgsql_result = PQgetResult (object->conn );
695
698
status = PQresultStatus (pgsql_result);
696
699
697
- zend_update_property_long (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" resultStatus" ), status);
698
-
699
- switch (status)
700
- {
701
- case PGRES_EMPTY_QUERY:
702
- case PGRES_BAD_RESPONSE:
703
- case PGRES_NONFATAL_ERROR:
704
- case PGRES_FATAL_ERROR:
705
- err_msg = PQerrorMessage (object->conn );
706
- set_error_diag (object, pgsql_result);
707
- PQclear (pgsql_result);
708
- ZVAL_FALSE (&return_value);
709
- swoole_event_del (object->socket );
710
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), err_msg);
711
- PHPCoroutine::resume_m (context, &return_value);
712
- if (error != 0 ) {
713
- php_swoole_fatal_error (E_WARNING, " socket error. Error: %s [%d]" , strerror (error), error);
714
- }
715
- break ;
716
- case PGRES_COMMAND_OK: /* successful command that did not return rows */
717
- /* Wait to finish sending buffer */
718
- // res = PQflush(object->conn);
719
- PQclear (pgsql_result);
720
- swoole_event_del (object->socket );
721
- ZVAL_TRUE (&return_value);
722
- zend_update_property_null (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ));
723
- zend_update_property_null (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" resultDiag" ));
724
- PHPCoroutine::resume_m (context, &return_value);
725
- if (error != 0 ) {
726
- php_swoole_fatal_error (E_WARNING, " socket error. Error: %s [%d]" , strerror (error), error);
727
- }
728
- break ;
729
- default :
730
- PQclear (pgsql_result);
731
- swoole_event_del (object->socket );
732
- ZVAL_FALSE (&return_value);
733
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), " Bad result returned to prepare" );
734
- PHPCoroutine::resume_m (context, &return_value);
735
- if (error != 0 ) {
736
- php_swoole_fatal_error (E_WARNING, " socket error. Error: %s [%d]" , strerror (error), error);
737
- }
738
- break ;
700
+ zend_update_property_long (
701
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" resultStatus" ), status);
702
+
703
+ switch (status) {
704
+ case PGRES_EMPTY_QUERY:
705
+ case PGRES_BAD_RESPONSE:
706
+ case PGRES_NONFATAL_ERROR:
707
+ case PGRES_FATAL_ERROR:
708
+ err_msg = PQerrorMessage (object->conn );
709
+ set_error_diag (object, pgsql_result);
710
+ PQclear (pgsql_result);
711
+ ZVAL_FALSE (&return_value);
712
+ swoole_event_del (object->socket );
713
+ zend_update_property_string (
714
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ), err_msg);
715
+ PHPCoroutine::resume_m (context, &return_value);
716
+ if (error != 0 ) {
717
+ php_swoole_fatal_error (E_WARNING, " socket error. Error: %s [%d]" , strerror (error), error);
718
+ }
719
+ break ;
720
+ case PGRES_COMMAND_OK: /* successful command that did not return rows */
721
+ /* Wait to finish sending buffer */
722
+ // res = PQflush(object->conn);
723
+ PQclear (pgsql_result);
724
+ swoole_event_del (object->socket );
725
+ ZVAL_TRUE (&return_value);
726
+ zend_update_property_null (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" error" ));
727
+ zend_update_property_null (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (object->object ), ZEND_STRL (" resultDiag" ));
728
+ PHPCoroutine::resume_m (context, &return_value);
729
+ if (error != 0 ) {
730
+ php_swoole_fatal_error (E_WARNING, " socket error. Error: %s [%d]" , strerror (error), error);
731
+ }
732
+ break ;
733
+ default :
734
+ PQclear (pgsql_result);
735
+ swoole_event_del (object->socket );
736
+ ZVAL_FALSE (&return_value);
737
+ zend_update_property_string (swoole_postgresql_coro_ce,
738
+ SW_Z8_OBJ_P (object->object ),
739
+ ZEND_STRL (" error" ),
740
+ " Bad result returned to prepare" );
741
+ PHPCoroutine::resume_m (context, &return_value);
742
+ if (error != 0 ) {
743
+ php_swoole_fatal_error (E_WARNING, " socket error. Error: %s [%d]" , strerror (error), error);
744
+ }
745
+ break ;
739
746
}
740
747
(void ) res;
741
748
@@ -744,7 +751,7 @@ static int prepare_result_parse(pg_object *object) {
744
751
745
752
static bool swoole_pgsql_wait_write_ready (PGconn *pgsql, pg_object *object, zval *zthis) {
746
753
int retval = 0 ;
747
- object->co = Coroutine::get_current_safe ();;
754
+ object->co = Coroutine::get_current_safe ();
748
755
749
756
ON_SCOPE_EXIT {
750
757
if (object->socket ->isset_writable_event ()) {
@@ -759,12 +766,16 @@ static bool swoole_pgsql_wait_write_ready(PGconn *pgsql, pg_object *object, zval
759
766
}
760
767
object->co ->yield_ex (object->timeout );
761
768
if (object->co ->is_canceled ()) {
762
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (zthis), ZEND_STRL (" error" ),
769
+ zend_update_property_string (swoole_postgresql_coro_ce,
770
+ SW_Z8_OBJ_P (zthis),
771
+ ZEND_STRL (" error" ),
763
772
swoole_strerror (SW_ERROR_CO_CANCELED));
764
773
return false ;
765
774
}
766
775
if (object->co ->is_timedout ()) {
767
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (zthis), ZEND_STRL (" error" ),
776
+ zend_update_property_string (swoole_postgresql_coro_ce,
777
+ SW_Z8_OBJ_P (zthis),
778
+ ZEND_STRL (" error" ),
768
779
swoole_strerror (SW_ERROR_CO_TIMEDOUT));
769
780
return false ;
770
781
}
@@ -1126,16 +1137,16 @@ static PHP_METHOD(swoole_postgresql_coro, numRows) {
1126
1137
RETVAL_LONG (PQntuples (pgsql_result));
1127
1138
}
1128
1139
1129
- // query's field count
1140
+ // query's field count
1130
1141
static PHP_METHOD (swoole_postgresql_coro, fieldCount) {
1131
1142
zval *result;
1132
1143
PGresult *pgsql_result;
1133
1144
1134
- ZEND_PARSE_PARAMETERS_START (1 ,1 )
1145
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
1135
1146
Z_PARAM_RESOURCE (result)
1136
1147
ZEND_PARSE_PARAMETERS_END_EX (RETURN_FALSE);
1137
1148
1138
- if ((pgsql_result = (PGresult *)zend_fetch_resource (Z_RES_P (result), " PostgreSQL result" , le_result)) == NULL ) {
1149
+ if ((pgsql_result = (PGresult *) zend_fetch_resource (Z_RES_P (result), " PostgreSQL result" , le_result)) == NULL ) {
1139
1150
RETURN_FALSE;
1140
1151
}
1141
1152
@@ -1513,7 +1524,8 @@ static PHP_METHOD(swoole_postgresql_coro, escape) {
1513
1524
size_t new_len = PQescapeStringConn (object->conn , result->val , str, l_str, &error);
1514
1525
1515
1526
if (new_len == 0 || error) {
1516
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" error" ), PQerrorMessage (pgsql));
1527
+ zend_update_property_string (
1528
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" error" ), PQerrorMessage (pgsql));
1517
1529
zend_update_property_long (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" errCode" ), error);
1518
1530
zend_string_free (result);
1519
1531
RETURN_FALSE;
@@ -1538,7 +1550,8 @@ static PHP_METHOD(swoole_postgresql_coro, escapeLiteral) {
1538
1550
1539
1551
tmp = PQescapeLiteral (pgsql, str, l_str);
1540
1552
if (tmp == nullptr ) {
1541
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" error" ), PQerrorMessage (pgsql));
1553
+ zend_update_property_string (
1554
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" error" ), PQerrorMessage (pgsql));
1542
1555
1543
1556
RETURN_FALSE;
1544
1557
}
@@ -1561,7 +1574,8 @@ static PHP_METHOD(swoole_postgresql_coro, escapeIdentifier) {
1561
1574
1562
1575
tmp = PQescapeIdentifier (pgsql, str, l_str);
1563
1576
if (tmp == nullptr ) {
1564
- zend_update_property_string (swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" error" ), PQerrorMessage (pgsql));
1577
+ zend_update_property_string (
1578
+ swoole_postgresql_coro_ce, SW_Z8_OBJ_P (ZEND_THIS), ZEND_STRL (" error" ), PQerrorMessage (pgsql));
1565
1579
1566
1580
RETURN_FALSE;
1567
1581
}
0 commit comments