* Prepare event trigger state for a new complete query to run, if necessary; * returns whether this was done. If it was, EventTriggerEndCompleteQuery must * be called when the query is done, regardless of whether it succeeds or fails * -- so use of a PG_TRY block is mandatory. */
| 1104 | * -- so use of a PG_TRY block is mandatory. |
| 1105 | */ |
| 1106 | bool |
| 1107 | EventTriggerBeginCompleteQuery(void) |
| 1108 | { |
| 1109 | EventTriggerQueryState *state; |
| 1110 | MemoryContext cxt; |
| 1111 | |
| 1112 | /* |
| 1113 | * Currently, sql_drop, table_rewrite, ddl_command_end events are the only |
| 1114 | * reason to have event trigger state at all; so if there are none, don't |
| 1115 | * install one. |
| 1116 | */ |
| 1117 | if (!trackDroppedObjectsNeeded()) |
| 1118 | return false; |
| 1119 | |
| 1120 | cxt = AllocSetContextCreate(TopMemoryContext, |
| 1121 | "event trigger state", |
| 1122 | ALLOCSET_DEFAULT_SIZES); |
| 1123 | state = MemoryContextAlloc(cxt, sizeof(EventTriggerQueryState)); |
| 1124 | state->cxt = cxt; |
| 1125 | slist_init(&(state->SQLDropList)); |
| 1126 | state->in_sql_drop = false; |
| 1127 | state->table_rewrite_oid = InvalidOid; |
| 1128 | |
| 1129 | state->commandCollectionInhibited = currentEventTriggerState ? |
| 1130 | currentEventTriggerState->commandCollectionInhibited : false; |
| 1131 | state->currentCommand = NULL; |
| 1132 | state->commandList = NIL; |
| 1133 | state->previous = currentEventTriggerState; |
| 1134 | currentEventTriggerState = state; |
| 1135 | |
| 1136 | return true; |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | * Query completed (or errored out) -- clean up local state, return to previous |
no test coverage detected