Skip to content
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

Remove support for PostgreSQL < 12. #82

Merged
merged 2 commits into from
Aug 5, 2024
Merged
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: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ variety of nefarious or otherwise undesireable actions. However, these actions
will be logged providing an audit trail, which could also be used to trigger
alerts.

This extension supports PostgreSQL versions 9.4 and higher.
This extension supports PostgreSQL versions 12 and higher. Prior versions of
PostgreSQL are supported by prior versions of set_user.

## Post-Execution Hooks

Expand Down
123 changes: 28 additions & 95 deletions src/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@
* - Removes OID column
*/
#if PG_VERSION_NUM >= 120000

dwsteele marked this conversation as resolved.
Show resolved Hide resolved
#ifndef _PU_HOOK
#define _PU_HOOK \
static void PU_hook(PlannedStmt *pstmt, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
QueryEnvironment *queryEnv, \
DestReceiver *dest, char *completionTag)

#define _prev_hook \
prev_hook(pstmt, queryString, context, params, queryEnv, dest, completionTag)

#define _standard_ProcessUtility \
standard_ProcessUtility(pstmt, queryString, context, params, queryEnv, dest, completionTag)

#endif

#include "utils/varlena.h"
#define parsetree ((Node *) pstmt->utilityStmt)

#define HEAP_TUPLE_GET_OID

/*
Expand Down Expand Up @@ -112,97 +131,6 @@ _heap_tuple_get_oid(HeapTuple tuple, Oid catalogID)

#include "access/table.h"
#define OBJECTADDRESS
#endif /* 12+ */

/*
* PostgreSQL version 10+
*
* - Introduces PlannedStmt struct
* - Introduces varlena.h
*/
#if PG_VERSION_NUM >= 100000
#ifndef _PU_HOOK
#define _PU_HOOK \
static void PU_hook(PlannedStmt *pstmt, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
QueryEnvironment *queryEnv, \
DestReceiver *dest, char *completionTag)

#define _prev_hook \
prev_hook(pstmt, queryString, context, params, queryEnv, dest, completionTag)

#define _standard_ProcessUtility \
standard_ProcessUtility(pstmt, queryString, context, params, queryEnv, dest, completionTag)

#endif

#include "utils/varlena.h"
#define parsetree ((Node *) pstmt->utilityStmt)

#endif /* 10+ */

/*
* PostgreSQL version 9.5+
*
* - Introduces two-argument GetUserNameFromId
*/
#if PG_VERSION_NUM >= 90500
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid, false)

#ifndef INITSESSIONUSER
#define INITSESSIONUSER
#define _InitializeSessionUserId(name,ouserid) InitializeSessionUserId(name,ouserid)
#endif

#endif /* 9.5+ */

/*
* PostgreSQL version 9.4+
*
* Lowest supported version.
*/
#if PG_VERSION_NUM >= 90400
#ifndef _PU_HOOK
#define _PU_HOOK \
static void PU_hook(Node *parsetree, const char *queryString, \
ProcessUtilityContext context, ParamListInfo params, \
DestReceiver *dest, char *completionTag)

#define _prev_hook \
prev_hook(parsetree, queryString, context, params, dest, completionTag)

#define _standard_ProcessUtility \
standard_ProcessUtility(parsetree, queryString, context, params, dest, completionTag)
#endif

#ifndef GETUSERNAMEFROMID
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid)
#endif

# ifndef HEAP_TUPLE_GET_OID
static inline Oid
_heap_tuple_get_oid(HeapTuple tup, Oid catalogId)
{
return HeapTupleGetOid(tup);
}
# endif

#ifndef TABLEOPEN
#define table_open(r, l) heap_open(r, l)
#define table_close(r, l) heap_close(r, l)
#endif

#include "access/heapam.h"

#ifndef OBJECTADDRESS
#include "utils/tqual.h"
#endif

#ifndef Anum_pg_proc_oid
#include "access/sysattr.h"
#define Anum_pg_proc_oid ObjectIdAttributeNumber
#define Anum_pg_authid_oid ObjectIdAttributeNumber
#endif

/*
* _scan_key_init
Expand All @@ -228,14 +156,19 @@ _scan_key_init(ScanKey entry,
}
}

// Introduces two-argument GetUserNameFromId
#define GETUSERNAMEFROMID(ouserid) GetUserNameFromId(ouserid, false)

#ifndef INITSESSIONUSER
#define _InitializeSessionUserId(name,ouserid) InitializeSessionUserId(name)
#define INITSESSIONUSER
#define _InitializeSessionUserId(name,ouserid) InitializeSessionUserId(name,ouserid)

#endif

#endif /* 9.4 */
#endif /* 12+ */

#if !defined(PG_VERSION_NUM) || PG_VERSION_NUM < 90400
#error "This extension only builds with PostgreSQL 9.4 or later"
#if !defined(PG_VERSION_NUM) || PG_VERSION_NUM < 120000
#error "This extension only builds with PostgreSQL 12 or later"
#endif

/* Use our version-specific static declaration here */
Expand Down