Skip to content

Commit

Permalink
Add safety check in event triggers to check if pg_duckdb is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Oct 14, 2024
1 parent 03d60f0 commit 8383320
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/pgduckdb_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ duckdb_create_table_trigger(PG_FUNCTION_ARGS) {
if (!CALLED_AS_EVENT_TRIGGER(fcinfo)) /* internal error */
elog(ERROR, "not fired by event trigger manager");

if (!pgduckdb::IsExtensionRegistered()) {
/*
* We're not installed, so don't mess with the query. Normally this
* shouldn't happen, but better safe than sorry.
*/
PG_RETURN_NULL();
}

EventTriggerData *trigger_data = (EventTriggerData *)fcinfo->context;
Node *parsetree = trigger_data->parsetree;

Expand Down Expand Up @@ -315,6 +323,14 @@ duckdb_drop_trigger(PG_FUNCTION_ARGS) {
if (!CALLED_AS_EVENT_TRIGGER(fcinfo)) /* internal error */
elog(ERROR, "not fired by event trigger manager");

if (!pgduckdb::IsExtensionRegistered()) {
/*
* We're not installed, so don't mess with the query. Normally this
* shouldn't happen, but better safe than sorry.
*/
PG_RETURN_NULL();
}

SPI_connect();

/*
Expand Down Expand Up @@ -469,6 +485,14 @@ duckdb_alter_table_trigger(PG_FUNCTION_ARGS) {
if (!CALLED_AS_EVENT_TRIGGER(fcinfo)) /* internal error */
elog(ERROR, "not fired by event trigger manager");

if (!pgduckdb::IsExtensionRegistered()) {
/*
* We're not installed, so don't mess with the query. Normally this
* shouldn't happen, but better safe than sorry.
*/
PG_RETURN_NULL();
}

SPI_connect();

/*
Expand Down Expand Up @@ -566,6 +590,15 @@ Datum
duckdb_grant_trigger(PG_FUNCTION_ARGS) {
if (!CALLED_AS_EVENT_TRIGGER(fcinfo)) /* internal error */
elog(ERROR, "not fired by event trigger manager");

if (!pgduckdb::IsExtensionRegistered()) {
/*
* We're not installed, so don't mess with the query. Normally this
* shouldn't happen, but better safe than sorry.
*/
PG_RETURN_NULL();
}

EventTriggerData *trigdata = (EventTriggerData *)fcinfo->context;
Node *parsetree = trigdata->parsetree;
if (!IsA(parsetree, GrantStmt)) {
Expand Down

0 comments on commit 8383320

Please sign in to comment.