Skip to content

Commit

Permalink
Set the resetTDSConnectionFlag with inline handler in tdsprotocol ins…
Browse files Browse the repository at this point in the history
…tead of rondevouz variable
  • Loading branch information
Sharath BP committed Aug 6, 2024
1 parent 60589ef commit 6d856fb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 30 deletions.
3 changes: 1 addition & 2 deletions contrib/babelfishpg_tds/src/backend/tds/tds_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +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->is_rpc_request = &isRPCRequest;
pltsql_plugin_handler_ptr->reset_tds_connection_flag = &resetTdsConnectionFlag;
pltsql_plugin_handler_ptr->set_reset_tds_connection_flag = &SetResetTDSConnectionFlag;

invalidate_stat_table_hook = invalidate_stat_table;
guc_newval_hook = TdsSetGucStatVariable;
Expand Down
12 changes: 9 additions & 3 deletions contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ typedef ResetConnectionData *ResetConnection;
* Local structures
*/
TdsRequestCtrlData *TdsRequestCtrl = NULL;
bool resetTdsConnectionFlag;
bool isRPCRequest;

ResetConnection resetCon = NULL;
static bool resetTdsConnectionFlag = false;

/* Local functions */
static void ResetTDSConnection(void);
Expand Down Expand Up @@ -164,6 +163,14 @@ ResetTDSConnection(void)
TdsSendEnvChange(TDS_ENVID_RESETCON, NULL, NULL);
}

/*
* SetResetTDSConnectionFlag - Sets reset tds connection flag
*/
void SetResetTDSConnectionFlag()
{
resetTdsConnectionFlag = true;
}

/*
* GetTDSRequest - Fetch and parse a TDS packet and generate a TDS request that
* can be processed later.
Expand Down Expand Up @@ -224,7 +231,6 @@ GetTDSRequest(bool *resetProtocol)
*/
HOLD_CANCEL_INTERRUPTS();
ret = TdsReadNextRequest(&message, &status, &messageType);
isRPCRequest = messageType == TDS_RPC;
RESUME_CANCEL_INTERRUPTS();

if (ret != 0)
Expand Down
3 changes: 1 addition & 2 deletions contrib/babelfishpg_tds/src/include/tds_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ typedef struct
} TdsRequestCtrlData;

extern TdsRequestCtrlData *TdsRequestCtrl;
extern bool resetTdsConnectionFlag;
extern bool isRPCRequest;
extern void SetResetTDSConnectionFlag(void);

#endif /* TDS_PROTOCOL_H */
6 changes: 2 additions & 4 deletions contrib/babelfishpg_tsql/src/pltsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,8 @@ typedef struct PLtsql_protocol_plugin

char *(*get_physical_schema_name) (char *db_name, const char *schema_name);

void (*set_reset_tds_connection_flag) ();

/* Session level GUCs */
bool quoted_identifier;
bool arithabort;
Expand All @@ -1774,10 +1776,6 @@ typedef struct PLtsql_protocol_plugin
int datefirst;
int lock_timeout;
const char *language;

bool *reset_tds_connection_flag;
bool *is_rpc_request;

} PLtsql_protocol_plugin;

/*
Expand Down
10 changes: 1 addition & 9 deletions contrib/babelfishpg_tsql/src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -4184,15 +4184,7 @@ sp_reset_connection_internal(PG_FUNCTION_ARGS)
{
if (*pltsql_protocol_plugin_ptr)
{
if (*(*pltsql_protocol_plugin_ptr)->is_rpc_request)
{
*(*pltsql_protocol_plugin_ptr)->reset_tds_connection_flag = true;
}
else
{
*(*pltsql_protocol_plugin_ptr)->reset_tds_connection_flag = false;
elog(ERROR, "Invalid object name 'sp_reset_connection'");
}
(*pltsql_protocol_plugin_ptr)->set_reset_tds_connection_flag();
}

PG_RETURN_VOID();
Expand Down
13 changes: 3 additions & 10 deletions test/JDBC/expected/Test-sp_reset_connection.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ int#!#int

EXEC sys.sp_reset_connection
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Invalid object name 'sp_reset_connection')~~


SELECT * from #babel_temp_table
Go
~~START~~
int#!#int
1#!#100
2#!#200
3#!#300
~~END~~
~~ERROR (Code: 33557097)~~

~~ERROR (Message: relation "#babel_temp_table" does not exist)~~

0 comments on commit 6d856fb

Please sign in to comment.