Skip to content

Commit 4b99fed

Browse files
committed
libpq: Add service name to PGconn and PQservice()
This commit adds one field to PGconn for the database service name (if any), with PQservice() as routine to retrieve it. Like the other routines of this area, NULL is returned as result if the connection is NULL. A follow-up patch will make use of this feature to be able to display the service name in the psql prompt. Author: Michael Banck Reviewed-by: Greg Sabino Mullane Discusion: https://postgr.es/m/6723c612.050a0220.1567f4.b94a@mx.google.com
1 parent 3f06324 commit 4b99fed

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,26 @@ char *PQport(const PGconn *conn);
25302530
</listitem>
25312531
</varlistentry>
25322532

2533+
<varlistentry id="libpq-PQservice">
2534+
<term><function>PQservice</function><indexterm><primary>PQservice</primary></indexterm></term>
2535+
2536+
<listitem>
2537+
<para>
2538+
Returns the service of the active connection.
2539+
2540+
<synopsis>
2541+
char *PQservice(const PGconn *conn);
2542+
</synopsis>
2543+
</para>
2544+
2545+
<para>
2546+
<xref linkend="libpq-PQservice"/> returns <symbol>NULL</symbol> if the
2547+
<parameter>conn</parameter> argument is <symbol>NULL</symbol>.
2548+
Otherwise, if there was no service provided, it returns an empty string.
2549+
</para>
2550+
</listitem>
2551+
</varlistentry>
2552+
25332553
<varlistentry id="libpq-PQtty">
25342554
<term><function>PQtty</function><indexterm><primary>PQtty</primary></indexterm></term>
25352555

src/interfaces/libpq/exports.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,4 @@ PQcancelFinish 202
205205
PQsocketPoll 203
206206
PQsetChunkedRowsMode 204
207207
PQgetCurrentTimeUSec 205
208+
PQservice 206

src/interfaces/libpq/fe-connect.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ typedef struct _internalPQconninfoOption
190190

191191
static const internalPQconninfoOption PQconninfoOptions[] = {
192192
{"service", "PGSERVICE", NULL, NULL,
193-
"Database-Service", "", 20, -1},
193+
"Database-Service", "", 20,
194+
offsetof(struct pg_conn, pgservice)},
194195

195196
{"user", "PGUSER", NULL, NULL,
196197
"Database-User", "", 20,
@@ -7040,6 +7041,14 @@ PQdb(const PGconn *conn)
70407041
return conn->dbName;
70417042
}
70427043

7044+
char *
7045+
PQservice(const PGconn *conn)
7046+
{
7047+
if (!conn)
7048+
return NULL;
7049+
return conn->pgservice;
7050+
}
7051+
70437052
char *
70447053
PQuser(const PGconn *conn)
70457054
{

src/interfaces/libpq/libpq-fe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ extern int PQrequestCancel(PGconn *conn);
385385

386386
/* Accessor functions for PGconn objects */
387387
extern char *PQdb(const PGconn *conn);
388+
extern char *PQservice(const PGconn *conn);
388389
extern char *PQuser(const PGconn *conn);
389390
extern char *PQpass(const PGconn *conn);
390391
extern char *PQhost(const PGconn *conn);

src/interfaces/libpq/libpq-int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ struct pg_conn
394394
char *fbappname; /* fallback application name */
395395
char *dbName; /* database name */
396396
char *replication; /* connect as the replication standby? */
397+
char *pgservice; /* Postgres service, if any */
397398
char *pguser; /* Postgres username and password, if any */
398399
char *pgpass;
399400
char *pgpassfile; /* path to a file containing password(s) */

0 commit comments

Comments
 (0)