Skip to content

Commit

Permalink
Add pg10 compatibility for ProcessUtilityHook
Browse files Browse the repository at this point in the history
Commit ab1f0c8 introduced the use of PlannedStatement in the
ProcessUtilityHook. This change only affects versions >9.6.

Commit 01fd6f8 introduced an extra argument (QueryEnvironment) in the
ProcessUtilityHook. This change only affects versions >9.6.

Rather than check for both changes, we assume that the PlannedStatement feature
encapsulates both >9.6 changes to further ifdef magic.
  • Loading branch information
mpalmi committed Apr 20, 2017
1 parent b89fbf7 commit f78d437
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions set_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@
#define HAS_TWO_ARG_GETUSERNAMEFROMID
#define HAS_PROCESSUTILITYCONTEXT

#elif PG_VERSION_NUM < 100000
/* 9.6 */
#define HAS_HTUP_DETAILS
#define HAS_ALTER_SYSTEM
#define HAS_COPY_PROGRAM
#define HAS_TWO_ARG_GETUSERNAMEFROMID
#define HAS_PROCESSUTILITYCONTEXT

#else
/* master */
#define HAS_HTUP_DETAILS
#define HAS_ALTER_SYSTEM
#define HAS_COPY_PROGRAM
#define HAS_TWO_ARG_GETUSERNAMEFROMID
#define HAS_PROCESSUTILITYCONTEXT
#define HAS_PSTMT

#endif

Expand Down Expand Up @@ -108,15 +117,23 @@ static bool Block_LS = false;
static bool Block_SU = false;

#ifdef HAS_TWO_ARG_GETUSERNAMEFROMID
/* 9.5 & master */
/* 9.5 - master */
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid, false)
#else
/* 9.1 - 9.4 */
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid)
#endif

#ifdef HAS_PSTMT
/* 10 & up */
static void PU_hook(PlannedStmt *pstmt, const char *queryString,
ProcessUtilityContext context, ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest, char *completionTag);
#else
/* < 10 */
#ifdef HAS_PROCESSUTILITYCONTEXT
/* 9.3 & up */
/* 9.3 - 9.6 */
static void PU_hook(Node *parsetree, const char *queryString,
ProcessUtilityContext context, ParamListInfo params,
DestReceiver *dest, char *completionTag);
Expand All @@ -126,6 +143,7 @@ static void PU_hook(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
#endif
#endif

extern Datum set_user(PG_FUNCTION_ARGS);
void _PG_init(void);
Expand Down Expand Up @@ -337,8 +355,16 @@ _PG_fini(void)
ProcessUtility_hook = prev_hook;
}

#ifdef HAS_PSTMT
/* 10 & up */
static void PU_hook(PlannedStmt *pstmt, const char *queryString,
ProcessUtilityContext context, ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest, char *completionTag)
#else
/* < 10 */
#ifdef HAS_PROCESSUTILITYCONTEXT
/* 9.3 & up */
/* 9.3 - 9.6 */
static void
PU_hook(Node *parsetree, const char *queryString,
ProcessUtilityContext context, ParamListInfo params,
Expand All @@ -350,7 +376,12 @@ PU_hook(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag)
#endif
#endif
{

#ifdef HAS_PSTMT
Node *parsetree = pstmt->utilityStmt;
#endif
/* if set_user has been used to transition, enforce set_user GUCs */
if (save_OldUserId != InvalidOid)
{
Expand Down Expand Up @@ -393,6 +424,17 @@ PU_hook(Node *parsetree, const char *queryString,
* Now pass-off handling either to the previous ProcessUtility hook
* or to the standard ProcessUtility.
*/
#ifdef HAS_PSTMT
/* 10 & up */
if (prev_hook)
prev_hook(pstmt, queryString, context, params,
queryEnv, dest, completionTag);
else
standard_ProcessUtility(pstmt, queryString,
context, params, queryEnv,
dest, completionTag);
#else
/* < 10 */
#ifdef HAS_PROCESSUTILITYCONTEXT
/* 9.3 & up */
if (prev_hook)
Expand All @@ -412,4 +454,5 @@ PU_hook(Node *parsetree, const char *queryString,
params, isTopLevel,
dest, completionTag);
#endif
#endif
}

0 comments on commit f78d437

Please sign in to comment.