Skip to content

Commit

Permalink
Remove support for PostgreSQL < 12. (#82)
Browse files Browse the repository at this point in the history
These versions are EOL so it make sense to remove them.

Reviewed by Keith Fiske (@keithf4).
  • Loading branch information
dwsteele authored Aug 5, 2024
1 parent 7f063e5 commit b89e978
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 96 deletions.
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

#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

0 comments on commit b89e978

Please sign in to comment.