diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index d82f8cb2772..345784257a3 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -76,6 +76,8 @@ /* Hook for plugins to get control in ProcessUtility() */ ProcessUtility_hook_type ProcessUtility_hook = NULL; +CreateDbStmt_hook_type CreateDbStmt_hook = NULL; +DropDbStmt_hook_type DropDbStmt_hook = NULL; /* local function declarations */ static int ClassifyUtilityCommandAsReadOnly(Node *parsetree); @@ -778,8 +780,13 @@ standard_ProcessUtility(PlannedStmt *pstmt, */ if (sql_dialect != SQL_DIALECT_TSQL) { PreventInTransactionBlock(isTopLevel, "CREATE DATABASE"); + createdb(pstate, (CreatedbStmt *) parsetree); + } + else + { + if (CreateDbStmt_hook) + (*CreateDbStmt_hook)(pstate, pstmt); } - createdb(pstate, (CreatedbStmt *) parsetree); break; case T_AlterDatabaseStmt: @@ -804,8 +811,13 @@ standard_ProcessUtility(PlannedStmt *pstmt, */ if (sql_dialect != SQL_DIALECT_TSQL) { PreventInTransactionBlock(isTopLevel, "DROP DATABASE"); + DropDatabase(pstate, (DropdbStmt *) parsetree); + } + else + { + if (DropDbStmt_hook) + (*DropDbStmt_hook)(pstmt); } - DropDatabase(pstate, (DropdbStmt *) parsetree); break; /* Query-level asynchronous notification */ diff --git a/src/include/tcop/utility.h b/src/include/tcop/utility.h index f9daf5b744c..c3a68a16f63 100644 --- a/src/include/tcop/utility.h +++ b/src/include/tcop/utility.h @@ -14,6 +14,7 @@ #ifndef UTILITY_H #define UTILITY_H +#include "parser/parse_node.h" #include "tcop/cmdtag.h" #include "tcop/tcopprot.h" @@ -109,4 +110,10 @@ extern LogStmtLevel GetCommandLogLevel(Node *parsetree); extern bool CommandIsReadOnly(PlannedStmt *pstmt); +typedef void (*CreateDbStmt_hook_type)(ParseState *pstate, PlannedStmt *pstmt); +extern PGDLLIMPORT CreateDbStmt_hook_type CreateDbStmt_hook; + +typedef void (*DropDbStmt_hook_type)(PlannedStmt *pstmt); +extern PGDLLIMPORT DropDbStmt_hook_type DropDbStmt_hook; + #endif /* UTILITY_H */