Use designated initialization

pull/7544/head
Jelte Fennema-Nio 2024-03-18 16:47:29 +01:00
parent 312051e93d
commit 5944672940
1 changed files with 54 additions and 65 deletions

View File

@ -129,48 +129,49 @@ static List * DropRoleStmtGetUnmarkDistributedParams(Node *parsetree);
* for CreateRoleStmt as Any_CreateRole, we name the struct that implements * for CreateRoleStmt as Any_CreateRole, we name the struct that implements
* SecLabelStmt for role objects as Role_SecLabel. * SecLabelStmt for role objects as Role_SecLabel.
*/ */
static const NonMainDbDistributeObjectOps Any_CreateRole = { static const NonMainDbDistributeObjectOps *operationArray[] = {
[T_CreateRoleStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = CreateRoleStmtGetMarkDistributedParams, .getMarkDistributedParams = CreateRoleStmtGetMarkDistributedParams,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = false .cannotBeExecutedInTransaction = false
}; },
static const NonMainDbDistributeObjectOps Any_DropRole = { [T_DropRoleStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = DropRoleStmtGetUnmarkDistributedParams, .getUnmarkDistributedParams = DropRoleStmtGetUnmarkDistributedParams,
.cannotBeExecutedInTransaction = false .cannotBeExecutedInTransaction = false
}; },
static const NonMainDbDistributeObjectOps Any_AlterRole = { [T_AlterRoleStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = false .cannotBeExecutedInTransaction = false
}; },
static const NonMainDbDistributeObjectOps Any_GrantRole = { [T_GrantRoleStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = false .cannotBeExecutedInTransaction = false
}; },
static const NonMainDbDistributeObjectOps Any_CreateDatabase = { [T_CreatedbStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = true .cannotBeExecutedInTransaction = true
}; },
static const NonMainDbDistributeObjectOps Any_DropDatabase = { [T_DropdbStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = true .cannotBeExecutedInTransaction = true
}; },
static const NonMainDbDistributeObjectOps Database_Grant = { [T_GrantStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = false .cannotBeExecutedInTransaction = false
}; },
static const NonMainDbDistributeObjectOps Role_SecLabel = { [T_SecLabelStmt] = &(NonMainDbDistributeObjectOps) {
.getMarkDistributedParams = NULL, .getMarkDistributedParams = NULL,
.getUnmarkDistributedParams = NULL, .getUnmarkDistributedParams = NULL,
.cannotBeExecutedInTransaction = false .cannotBeExecutedInTransaction = false
},
}; };
/* other static function declarations */ /* other static function declarations */
const NonMainDbDistributeObjectOps * GetNonMainDbDistributeObjectOps(Node *parsetree); const NonMainDbDistributeObjectOps * GetNonMainDbDistributeObjectOps(Node *parsetree);
static void MarkObjectDistributedGloballyOnMainDbs( static void MarkObjectDistributedGloballyOnMainDbs(
@ -273,28 +274,16 @@ RunPostprocessNonMainDBCommand(Node *parsetree)
const NonMainDbDistributeObjectOps * const NonMainDbDistributeObjectOps *
GetNonMainDbDistributeObjectOps(Node *parsetree) GetNonMainDbDistributeObjectOps(Node *parsetree)
{ {
NodeTag tag = nodeTag(parsetree);
if (tag >= lengthof(operationArray))
{
return NULL;
}
const NonMainDbDistributeObjectOps *ops = operationArray[tag];
switch (nodeTag(parsetree)) switch (nodeTag(parsetree))
{ {
case T_CreateRoleStmt:
{
return &Any_CreateRole;
}
case T_DropRoleStmt:
{
return &Any_DropRole;
}
case T_AlterRoleStmt:
{
return &Any_AlterRole;
}
case T_GrantRoleStmt:
{
return &Any_GrantRole;
}
case T_CreatedbStmt: case T_CreatedbStmt:
{ {
CreatedbStmt *stmt = castNode(CreatedbStmt, parsetree); CreatedbStmt *stmt = castNode(CreatedbStmt, parsetree);
@ -306,7 +295,7 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
*/ */
if (strcmp(stmt->dbname, MainDb) != 0) if (strcmp(stmt->dbname, MainDb) != 0)
{ {
return &Any_CreateDatabase; return ops;
} }
return NULL; return NULL;
@ -323,7 +312,7 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
*/ */
if (strcmp(stmt->dbname, MainDb) != 0) if (strcmp(stmt->dbname, MainDb) != 0)
{ {
return &Any_DropDatabase; return ops;
} }
return NULL; return NULL;
@ -337,7 +326,7 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
{ {
case OBJECT_DATABASE: case OBJECT_DATABASE:
{ {
return &Database_Grant; return ops;
} }
default: default:
@ -353,7 +342,7 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
{ {
case OBJECT_ROLE: case OBJECT_ROLE:
{ {
return &Role_SecLabel; return ops;
} }
default: default:
@ -362,7 +351,7 @@ GetNonMainDbDistributeObjectOps(Node *parsetree)
} }
default: default:
return NULL; return ops;
} }
} }