From 695afa2f9404515a9dcb829782157fdcf7ca408d Mon Sep 17 00:00:00 2001 From: Hari Babu Date: Wed, 27 Feb 2019 11:50:33 +1100 Subject: [PATCH 2/7] New TargetSessionAttrsType enum This new enum is useful to compare the requested session type instead of comparing it with string always. This may not show much improvement with current code, but it will be useful with further patches --- src/interfaces/libpq/fe-connect.c | 12 ++++++++---- src/interfaces/libpq/libpq-fe.h | 6 ++++++ src/interfaces/libpq/libpq-int.h | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index c68448786d..1dc22e6bdf 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -1243,8 +1243,11 @@ connectOptions2(PGconn *conn) */ if (conn->target_session_attrs) { - if (strcmp(conn->target_session_attrs, "any") != 0 - && strcmp(conn->target_session_attrs, "read-write") != 0) + if (strcmp(conn->target_session_attrs, "any") == 0) + conn->requested_session_type = SESSION_TYPE_ANY; + else if (strcmp(conn->target_session_attrs, "read-write") == 0) + conn->requested_session_type = SESSION_TYPE_READ_WRITE; + else { conn->status = CONNECTION_BAD; printfPQExpBuffer(&conn->errorMessage, @@ -3233,8 +3236,7 @@ keep_going: /* We will come back to here until there is * may just skip the test in that case. */ if (conn->sversion >= 70400 && - conn->target_session_attrs != NULL && - strcmp(conn->target_session_attrs, "read-write") == 0) + conn->requested_session_type != SESSION_TYPE_ANY) { /* * Save existing error messages across the PQsendQuery @@ -3540,6 +3542,8 @@ makeEmptyPGconn(void) conn->show_context = PQSHOW_CONTEXT_ERRORS; conn->sock = PGINVALID_SOCKET; + conn->requested_session_type = SESSION_TYPE_ANY; + /* * We try to send at least 8K at a time, which is the usual size of pipe * buffers on Unix systems. That way, when we are sending a large amount diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 50cfe266c6..6961d7ce8e 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -70,6 +70,12 @@ typedef enum CONNECTION_CHECK_TARGET /* Check if we have a proper target connection */ } ConnStatusType; +typedef enum +{ + SESSION_TYPE_ANY = 0, /* Any session (default) */ + SESSION_TYPE_READ_WRITE /* Read-write session */ +} TargetSessionAttrsType; + typedef enum { PGRES_POLLING_FAILED = 0, diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index dbe0f7e5c0..551120660c 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -365,6 +365,7 @@ struct pg_conn /* Type of connection to make. Possible values: any, read-write. */ char *target_session_attrs; + TargetSessionAttrsType requested_session_type; /* Optional file to write trace info to */ FILE *Pfdebug; -- 2.20.1.windows.1