Skip to content

Commit

Permalink
Add support for sys.sp_reset_connection stored procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharath BP committed Jul 19, 2024
1 parent 245d7ce commit d1df741
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/babelfishpg_tds/src/backend/tds/tds_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions contrib/babelfishpg_tds/src/include/tds_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ typedef struct

extern TdsRequestCtrlData *TdsRequestCtrl;

extern void ResetTDSConnection(void);

#endif /* TDS_PROTOCOL_H */
4 changes: 4 additions & 0 deletions contrib/babelfishpg_tsql/sql/sys_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/src/pltsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions contrib/babelfishpg_tsql/src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

0 comments on commit d1df741

Please sign in to comment.