Skip to content

Commit

Permalink
check that needed functions exists
Browse files Browse the repository at this point in the history
  • Loading branch information
remicollet committed Jun 13, 2023
1 parent c8b946f commit 6e1eccc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config9.m4
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ if test "$PHP_PQ" != "no"; then
PHP_SUBST(PQ_SHARED_LIBADD)

PQ_CHECK_FUNC(PQlibVersion)
PQ_CHECK_FUNC(PQprotocolVersion)
PQ_CHECK_FUNC(PQserverVersion)
PQ_CHECK_FUNC(PQconninfo)
PQ_CHECK_FUNC(PQsetSingleRowMode)

Expand Down
8 changes: 8 additions & 0 deletions src/php_pqconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,15 @@ static void php_pqconn_object_read_lib_version(void *o, zval *return_value)
RETVAL_STRING(ver);
}
#endif
#ifdef HAVE_PQPROTOCOLVERSION
static void php_pqconn_object_read_protocol_version(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;

RETVAL_LONG(PQprotocolVersion(obj->intern->conn));
}
#endif
#ifdef HAVE_PQSERVERVERSION
static void php_pqconn_object_read_server_version(void *o, zval *return_value)
{
php_pqconn_object_t *obj = o;
Expand All @@ -524,6 +527,7 @@ static void php_pqconn_object_read_server_version(void *o, zval *return_value)
}
RETVAL_STRING(ver);
}
#endif

static ZEND_RESULT_CODE php_pqconn_update_socket(zval *zobj, php_pqconn_object_t *obj)
{
Expand Down Expand Up @@ -2171,13 +2175,17 @@ PHP_MINIT_FUNCTION(pqconn)
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("libraryVersion"), (void *) &ph, sizeof(ph));
#endif

#ifdef HAVE_PQPROTOCOLVERSION
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("protocolVersion"), ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_protocol_version;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("protocolVersion"), (void *) &ph, sizeof(ph));
#endif

#ifdef HAVE_PQSERVERVERSION
zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("serverVersion"), ZEND_ACC_PUBLIC);
ph.read = php_pqconn_object_read_server_version;
zend_hash_str_add_mem(&php_pqconn_object_prophandlers, ZEND_STRL("serverVersion"), (void *) &ph, sizeof(ph));
#endif

zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD);
Expand Down

0 comments on commit 6e1eccc

Please sign in to comment.