Replace Integer Nodes with Boolean Nodes

Relevant PG commit:
941460fcf731a32e6a90691508d5cfa3d1f8eeaf
boolean_node
naisila 2022-07-26 13:18:20 +03:00
parent e5550fe990
commit f3ded60f10
2 changed files with 32 additions and 21 deletions

View File

@ -59,6 +59,7 @@ static char * CreateCreateOrAlterRoleCommand(const char *roleName,
CreateRoleStmt *createRoleStmt,
AlterRoleStmt *alterRoleStmt);
static DefElem * makeDefElemInt(char *name, int value);
static DefElem * makeDefElemBool(char *name, bool value);
static List * GenerateRoleOptionsList(HeapTuple tuple);
static List * GenerateGrantRoleStmtsFromOptions(RoleSpec *roleSpec, List *options);
static List * GenerateGrantRoleStmtsOfRole(Oid roleid);
@ -454,13 +455,13 @@ GenerateRoleOptionsList(HeapTuple tuple)
Form_pg_authid role = ((Form_pg_authid) GETSTRUCT(tuple));
List *options = NIL;
options = lappend(options, makeDefElemInt("superuser", role->rolsuper));
options = lappend(options, makeDefElemInt("createdb", role->rolcreatedb));
options = lappend(options, makeDefElemInt("createrole", role->rolcreaterole));
options = lappend(options, makeDefElemInt("inherit", role->rolinherit));
options = lappend(options, makeDefElemInt("canlogin", role->rolcanlogin));
options = lappend(options, makeDefElemInt("isreplication", role->rolreplication));
options = lappend(options, makeDefElemInt("bypassrls", role->rolbypassrls));
options = lappend(options, makeDefElemBool("superuser", role->rolsuper));
options = lappend(options, makeDefElemBool("createdb", role->rolcreatedb));
options = lappend(options, makeDefElemBool("createrole", role->rolcreaterole));
options = lappend(options, makeDefElemBool("inherit", role->rolinherit));
options = lappend(options, makeDefElemBool("canlogin", role->rolcanlogin));
options = lappend(options, makeDefElemBool("isreplication", role->rolreplication));
options = lappend(options, makeDefElemBool("bypassrls", role->rolbypassrls));
options = lappend(options, makeDefElemInt("connectionlimit", role->rolconnlimit));
/* load password from heap tuple, use NULL if not set */
@ -616,6 +617,16 @@ makeDefElemInt(char *name, int value)
}
/*
* makeDefElemBool creates a DefElem with boolean typed value with -1 as location.
*/
static DefElem *
makeDefElemBool(char *name, bool value)
{
return makeDefElem(name, (Node *) makeBoolean(value), -1);
}
/*
* GetDatabaseNameFromDbRoleSetting performs a lookup, and finds the database name
* associated DbRoleSetting Tuple

View File

@ -98,59 +98,59 @@ AppendRoleOption(StringInfo buf, ListCell *optionCell)
{
DefElem *option = (DefElem *) lfirst(optionCell);
if (strcmp(option->defname, "superuser") == 0 && intVal(option->arg))
if (strcmp(option->defname, "superuser") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " SUPERUSER");
}
else if (strcmp(option->defname, "superuser") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "superuser") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOSUPERUSER");
}
else if (strcmp(option->defname, "createdb") == 0 && intVal(option->arg))
else if (strcmp(option->defname, "createdb") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " CREATEDB");
}
else if (strcmp(option->defname, "createdb") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "createdb") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOCREATEDB");
}
else if (strcmp(option->defname, "createrole") == 0 && intVal(option->arg))
else if (strcmp(option->defname, "createrole") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " CREATEROLE");
}
else if (strcmp(option->defname, "createrole") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "createrole") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOCREATEROLE");
}
else if (strcmp(option->defname, "inherit") == 0 && intVal(option->arg))
else if (strcmp(option->defname, "inherit") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " INHERIT");
}
else if (strcmp(option->defname, "inherit") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "inherit") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOINHERIT");
}
else if (strcmp(option->defname, "canlogin") == 0 && intVal(option->arg))
else if (strcmp(option->defname, "canlogin") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " LOGIN");
}
else if (strcmp(option->defname, "canlogin") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "canlogin") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOLOGIN");
}
else if (strcmp(option->defname, "isreplication") == 0 && intVal(option->arg))
else if (strcmp(option->defname, "isreplication") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " REPLICATION");
}
else if (strcmp(option->defname, "isreplication") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "isreplication") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOREPLICATION");
}
else if (strcmp(option->defname, "bypassrls") == 0 && intVal(option->arg))
else if (strcmp(option->defname, "bypassrls") == 0 && boolVal(option->arg))
{
appendStringInfo(buf, " BYPASSRLS");
}
else if (strcmp(option->defname, "bypassrls") == 0 && !intVal(option->arg))
else if (strcmp(option->defname, "bypassrls") == 0 && !boolVal(option->arg))
{
appendStringInfo(buf, " NOBYPASSRLS");
}