Skip to content

Commit f3cc978

Browse files
committed
Add AUTHOID portability
1 parent 28dc32c commit f3cc978

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

contrib/postgres_fdw/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ configure_remote_session(PGconn *conn)
323323
* Temporarily switch off this option. Not all regression tests passes
324324
* correctly without including 'public' value in default search path.
325325
*/
326-
do_sql_command(conn, "SET search_path = pg_catalog");
326+
/* do_sql_command(conn, "SET search_path = pg_catalog"); */
327327

328328
/*
329329
* Set remote timezone; this is basically just cosmetic, since all

src/backend/commands/user.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,41 @@ DropRole(DropRoleStmt *stmt)
11301130
heap_close(pg_authid_rel, NoLock);
11311131
}
11321132

1133+
char *
1134+
get_rolename(Oid roleid)
1135+
{
1136+
HeapTuple tuple;
1137+
char *rolename;
1138+
1139+
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
1140+
1141+
if (!HeapTupleIsValid(tuple))
1142+
ereport(ERROR,
1143+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1144+
errmsg("role with oid\"%d\" does not exist", roleid)));
1145+
1146+
rolename = strdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname));
1147+
ReleaseSysCache(tuple);
1148+
return rolename;
1149+
}
1150+
1151+
Oid
1152+
get_roleid(const char *rolename)
1153+
{
1154+
HeapTuple tuple;
1155+
Oid roleid;
1156+
1157+
tuple = SearchSysCache1(AUTHNAME, CStringGetDatum(rolename));
1158+
1159+
if (!HeapTupleIsValid(tuple))
1160+
ereport(ERROR,
1161+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1162+
errmsg("role \"%s\" does not exist", rolename)));
1163+
1164+
roleid = HeapTupleGetOid(tuple);
1165+
ReleaseSysCache(tuple);
1166+
return roleid;
1167+
}
11331168
/*
11341169
* Rename role
11351170
*/

src/backend/nodes/outfuncs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <ctype.h>
2727

28+
#include "commands/user.h"
2829
#include "lib/stringinfo.h"
2930
#include "nodes/extensible.h"
3031
#include "nodes/plannodes.h"
@@ -35,8 +36,9 @@
3536
#include "utils/syscache.h"
3637

3738
#define NSP_NAME(nspoid) (get_namespace_name(nspoid))
38-
#define OID_TYPES_NUM (5)
39-
static const Oid oid_types[OID_TYPES_NUM] = {RELOID, TYPEOID, PROCOID, COLLOID, OPEROID};
39+
#define OID_TYPES_NUM (6)
40+
static const Oid oid_types[OID_TYPES_NUM] = {RELOID, TYPEOID, PROCOID, COLLOID,
41+
OPEROID, AUTHOID};
4042

4143
static bool portable_output = false;
4244
void
@@ -141,6 +143,10 @@ write_oid_field(StringInfo str, Oid oid)
141143
}
142144
break;
143145

146+
case AUTHOID:
147+
appendStringInfo(str, "%u %s", AUTHOID, get_rolename(oid));
148+
break;
149+
144150
default:
145151
Assert(0);
146152
break;

src/backend/nodes/readfuncs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
/* Portable-related dependencies */
3838
#include "catalog/namespace.h"
39+
#include "commands/user.h"
3940
#include "utils/builtins.h"
4041
#include "utils/lsyscache.h"
4142
#include "utils/syscache.h"
@@ -2896,6 +2897,16 @@ read_oid_field(char **token, int *length)
28962897
}
28972898
break;
28982899

2900+
case AUTHOID:
2901+
{
2902+
char *rolename;
2903+
2904+
*token = pg_strtok(length); /* get nspname */
2905+
rolename = nullable_string(*token, *length);
2906+
oid = get_roleid(rolename);
2907+
}
2908+
break;
2909+
28992910
default:
29002911
Assert(0);
29012912
break;

src/include/commands/user.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ extern ObjectAddress RenameRole(const char *oldname, const char *newname);
4242
extern void DropOwnedObjects(DropOwnedStmt *stmt);
4343
extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt);
4444
extern List *roleSpecsToIds(List *memberNames);
45+
extern char *get_rolename(Oid roid);
46+
extern Oid get_roleid(const char *rolename);
4547

4648
#endif /* USER_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy