From d1df741cb49a06d8af9fd20b2d04a0361a1d6bfa Mon Sep 17 00:00:00 2001 From: Sharath BP Date: Fri, 19 Jul 2024 11:16:01 +0000 Subject: [PATCH] Add support for sys.sp_reset_connection stored procedure --- contrib/babelfishpg_tds/src/backend/tds/tds_srv.c | 1 + .../babelfishpg_tds/src/backend/tds/tdsprotocol.c | 3 +-- contrib/babelfishpg_tds/src/include/tds_protocol.h | 2 ++ contrib/babelfishpg_tsql/sql/sys_procedures.sql | 4 ++++ contrib/babelfishpg_tsql/src/pltsql.h | 1 + contrib/babelfishpg_tsql/src/procedures.c | 14 ++++++++++++++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tds_srv.c b/contrib/babelfishpg_tds/src/backend/tds/tds_srv.c index 63ce388c47a..d4fe844a404 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tds_srv.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tds_srv.c @@ -202,6 +202,7 @@ pe_tds_init(void) pltsql_plugin_handler_ptr->set_context_info = &set_tds_context_info; pltsql_plugin_handler_ptr->get_datum_from_byte_ptr = &TdsBytePtrToDatum; pltsql_plugin_handler_ptr->get_datum_from_date_time_struct = &TdsDateTimeTypeToDatum; + pltsql_plugin_handler_ptr->reset_tds_connection = &ResetTDSConnection; invalidate_stat_table_hook = invalidate_stat_table; guc_newval_hook = TdsSetGucStatVariable; diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c b/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c index 038c244dda2..7e7705fd170 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c @@ -75,7 +75,6 @@ TdsRequestCtrlData *TdsRequestCtrl = NULL; ResetConnection resetCon = NULL; /* Local functions */ -static void ResetTDSConnection(void); static TDSRequest GetTDSRequest(bool *resetProtocol); static void ProcessTDSRequest(TDSRequest request); static void enable_statement_timeout(void); @@ -117,7 +116,7 @@ TdsDiscardAll() * buffers and structures. Additionally, it sends an environment change token * for RESETCON. */ -static void +void ResetTDSConnection(void) { const char *isolationOld; diff --git a/contrib/babelfishpg_tds/src/include/tds_protocol.h b/contrib/babelfishpg_tds/src/include/tds_protocol.h index a661cc181f1..62b847a9901 100644 --- a/contrib/babelfishpg_tds/src/include/tds_protocol.h +++ b/contrib/babelfishpg_tds/src/include/tds_protocol.h @@ -78,4 +78,6 @@ typedef struct extern TdsRequestCtrlData *TdsRequestCtrl; +extern void ResetTDSConnection(void); + #endif /* TDS_PROTOCOL_H */ diff --git a/contrib/babelfishpg_tsql/sql/sys_procedures.sql b/contrib/babelfishpg_tsql/sql/sys_procedures.sql index 51b03784dfe..4bdbbf4bb58 100644 --- a/contrib/babelfishpg_tsql/sql/sys_procedures.sql +++ b/contrib/babelfishpg_tsql/sql/sys_procedures.sql @@ -329,3 +329,7 @@ GRANT EXECUTE ON PROCEDURE sys.sp_dropextendedproperty TO PUBLIC; CREATE OR REPLACE PROCEDURE sys.sp_enum_oledb_providers() AS 'babelfishpg_tsql', 'sp_enum_oledb_providers_internal' LANGUAGE C; GRANT EXECUTE on PROCEDURE sys.sp_enum_oledb_providers() TO PUBLIC; + +CREATE OR REPLACE PROCEDURE sys.sp_reset_connection() +AS 'babelfishpg_tsql', 'sp_reset_connection_internal' LANGUAGE C; +GRANT EXECUTE ON PROCEDURE sys.sp_reset_connection() TO PUBLIC; diff --git a/contrib/babelfishpg_tsql/src/pltsql.h b/contrib/babelfishpg_tsql/src/pltsql.h index bbea96beec9..873e503d811 100644 --- a/contrib/babelfishpg_tsql/src/pltsql.h +++ b/contrib/babelfishpg_tsql/src/pltsql.h @@ -1678,6 +1678,7 @@ typedef struct PLtsql_protocol_plugin Datum (*sp_unprepare_callback) (PG_FUNCTION_ARGS); void (*reset_session_properties) (void); + void (*reset_tds_connection) (void); void (*sqlvariant_set_metadata) (bytea *result, int pgBaseType, int scale, int precision, int maxLen); void (*sqlvariant_get_metadata) (bytea *result, int pgBaseType, int *scale, diff --git a/contrib/babelfishpg_tsql/src/procedures.c b/contrib/babelfishpg_tsql/src/procedures.c index 940fed0a438..af2a57c69a4 100644 --- a/contrib/babelfishpg_tsql/src/procedures.c +++ b/contrib/babelfishpg_tsql/src/procedures.c @@ -78,6 +78,7 @@ PG_FUNCTION_INFO_V1(sp_babelfish_volatility); PG_FUNCTION_INFO_V1(sp_rename_internal); PG_FUNCTION_INFO_V1(sp_execute_postgresql); PG_FUNCTION_INFO_V1(sp_enum_oledb_providers_internal); +PG_FUNCTION_INFO_V1(sp_reset_connection_internal); PG_FUNCTION_INFO_V1(sp_renamedb_internal); extern void delete_cached_batch(int handle); @@ -4177,3 +4178,16 @@ sp_enum_oledb_providers_internal(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } + +Datum +sp_reset_connection_internal(PG_FUNCTION_ARGS) +{ + elog(DEBUG2, "Test sp_reset_connection_internal"); + + if ((*pltsql_protocol_plugin_ptr)->reset_tds_connection) + { + (*pltsql_protocol_plugin_ptr)->reset_tds_connection(); + } + + PG_RETURN_VOID(); +}