Skip to content

ext/pgsql: adding pg_service() alongside other connection infos. #18198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/pgsql/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ if test "$PHP_PGSQL" != "no"; then
PHP_CHECK_LIBRARY([pq], [PQclosePrepared],
[AC_DEFINE([HAVE_PG_CLOSE_STMT], [1], [PostgreSQL 17 or later])],,
[$PGSQL_LIBS])
PHP_CHECK_LIBRARY([pq], [PQservice],
[AC_DEFINE([HAVE_PG_SERVICE], [1], [PostgreSQL 18 or later])],,
[$PGSQL_LIBS])

old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $PGSQL_CFLAGS"
Expand Down
14 changes: 14 additions & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ PHP_FUNCTION(pg_close)
#define PHP_PG_HOST 6
#define PHP_PG_VERSION 7
#define PHP_PG_JIT 8
#define PHP_PG_SERVICE 9

/* php_pgsql_get_link_info */
static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
Expand Down Expand Up @@ -991,6 +992,12 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
PQclear(res);
return;
}
#if defined(HAVE_PG_SERVICE)
case PHP_PG_SERVICE: {
result = PQservice(pgsql);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this return NULL? If it does, then it will return the interned empty string, in which case the @refcount 1 annotation is wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's an exception for interned strings, but I don't believe so? I could be wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can return NULL.

break;
}
#endif
EMPTY_SWITCH_DEFAULT_CASE()
}
if (result) {
Expand Down Expand Up @@ -1047,6 +1054,13 @@ PHP_FUNCTION(pg_jit)
php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_JIT);
}

#if defined(HAVE_PG_SERVICE)
PHP_FUNCTION(pg_service)
{
php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_SERVICE);
}
#endif

/* Returns the value of a server parameter */
PHP_FUNCTION(pg_parameter_status)
{
Expand Down
3 changes: 3 additions & 0 deletions ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ function pg_version(?PgSql\Connection $connection = null): array {}
*/
function pg_jit(?PgSql\Connection $connection = null): array {}

#ifdef HAVE_PG_SERVICE
function pg_service(?PgSql\Connection $connection = null): string {}
#endif
/**
* @param PgSql\Connection|string $connection
* @refcount 1
Expand Down
14 changes: 13 additions & 1 deletion ext/pgsql/pgsql_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions ext/pgsql/tests/pg_service.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
PostgreSQL connection service field support
--EXTENSIONS--
pgsql
--SKIPIF--
<?php
include("inc/skipif.inc");
if (!function_exists("pg_service")) die("skip pg_service unsupported");
?>
--FILE--
<?php
include('inc/config.inc');

$db = pg_connect($conn_str);
var_dump(pg_service($db));
pg_close($db);
?>
--EXPECTF--
string(%d) "%A"
Loading