Skip to content

Commit

Permalink
Fix ansi and setconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
KushaalShroff committed Nov 26, 2024
1 parent d17cf0f commit 359fa3a
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 1 deletion.
11 changes: 11 additions & 0 deletions contrib/babelfishpg_tds/src/backend/tds/tdslogin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,17 @@ ProcessLoginFlags(LoginRequest loginInfo)
}
}

/*
* TdsResetLoginFlags - Resets the session properties which
* we provided during login time.
* Wrapper of ProcessLoginFlags, since we do not expose loginInfo.
*/
void
TdsResetLoginFlags()
{
ProcessLoginFlags(loginInfo);
}

/*
* ProcessLoginInternal - internal workhorse for processing login
* request.
Expand Down
2 changes: 2 additions & 0 deletions contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ ResetTDSConnection(void)
TdsResetCache();
TdsResponseReset();
TdsResetBcpOffset();
TdsResetLoginFlags();

/* Retore previous isolation level when not called by sys.sp_reset_connection. */
if (!resetTdsConnectionFlag)
{
Expand Down
1 change: 1 addition & 0 deletions contrib/babelfishpg_tds/src/include/tds_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ extern void TdsSendLoginAck(Port *port);
extern uint32_t GetClientTDSVersion(void);
extern char *get_tds_login_domainname(void);
extern void TdsSetDbContext(void);
extern void TdsResetLoginFlags(void);

/* Functions in backend/tds/tdsprotocol.c */
extern int TdsSocketBackend(void);
Expand Down
3 changes: 2 additions & 1 deletion contrib/babelfishpg_tsql/src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,8 @@ void
pltsql_validate_set_config_function(char *name, char *value)
{
if (strncmp(name, PLTSQL_SESSION_ISOLATION_LEVEL, strlen(PLTSQL_SESSION_ISOLATION_LEVEL)) == 0 ||
strncmp(name, PLTSQL_TRANSACTION_ISOLATION_LEVEL, strlen(PLTSQL_TRANSACTION_ISOLATION_LEVEL)) == 0)
strncmp(name, PLTSQL_TRANSACTION_ISOLATION_LEVEL, strlen(PLTSQL_TRANSACTION_ISOLATION_LEVEL)) == 0 ||
strncmp(name, "role", strlen("role")) == 0)
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
Expand Down
209 changes: 209 additions & 0 deletions test/JDBC/expected/Test-sp_reset_connection.out
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,212 @@ int

drop table babel_cursor_t1;
GO


-- GUCs testing
-- 1. Ansi defaults
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true);
GO
~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
off
~~END~~

~~START~~
text
on
~~END~~


SET ANSI_DEFAULTS ON
GO

SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true);
GO
~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~


-- reset
exec sys.sp_reset_connection
GO

SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true);
GO
~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
on
~~END~~

~~START~~
text
off
~~END~~

~~START~~
text
on
~~END~~


-- babelfish_showplan_all
SET babelfish_showplan_all ON
GO

-- explain output
SELECT 1;
GO
~~START~~
text
Query Text: SELECT 1
Result (cost=0.00..0.01 rows=1 width=4)
~~END~~

~~START~~
text
Babelfish T-SQL Batch Parsing Time: 0.085 ms
~~END~~


-- reset
exec sys.sp_reset_connection
GO

-- 1 output
SELECT 1;
GO
~~START~~
int
1
~~END~~



-- set_config testing.
-- search_path has source < PGC_S_SESSION in TSQL but it gets reset during ResetAll Gucs.
-- Whereas role does not get reset since it uses GUC_NO_RESET_ALL, so we should not allow
-- set_config for this option.
SELECT CURRENT_SETTING('search_path', true)
SELECT CURRENT_SETTING('role', true)
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
~~END~~

~~START~~
text
master_dbo
~~END~~


SELECT set_config('search_path', 'sys', false);
GO
~~START~~
text
sys
~~END~~

SELECT set_config('role', 'jdbc_user', false);
GO
~~START~~
text
~~ERROR (Code: 33557097)~~

~~ERROR (Message: set_config not allowed for option role)~~


-- reset
exec sp_reset_connection
GO

SELECT CURRENT_SETTING('search_path', true)
SELECT CURRENT_SETTING('role', true)
GO
~~START~~
text
master_dbo, "$user", sys, pg_catalog
~~END~~

~~START~~
text
master_dbo
~~END~~

72 changes: 72 additions & 0 deletions test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,76 @@ SELECT @@cursor_rows;
GO

drop table babel_cursor_t1;
GO

-- GUCs testing

-- 1. Ansi defaults
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true);
GO

SET ANSI_DEFAULTS ON
GO

SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true);
GO

-- reset
exec sys.sp_reset_connection
GO

SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_nulls', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_warnings', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_null_dflt_on', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.ansi_padding', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.implicit_transactions', true);
SELECT CURRENT_SETTING('babelfishpg_tsql.quoted_identifier', true);
GO

-- babelfish_showplan_all
SET babelfish_showplan_all ON
GO

-- explain output
SELECT 1;
GO

-- reset
exec sys.sp_reset_connection
GO

-- 1 output
SELECT 1;
GO

-- set_config testing.

-- search_path has source < PGC_S_SESSION in TSQL but it gets reset during ResetAll Gucs.
-- Whereas role does not get reset since it uses GUC_NO_RESET_ALL, so we should not allow
-- set_config for this option.
SELECT CURRENT_SETTING('search_path', true)
SELECT CURRENT_SETTING('role', true)
GO

SELECT set_config('search_path', 'sys', false);
GO
SELECT set_config('role', 'jdbc_user', false);
GO

-- reset
exec sp_reset_connection
GO

SELECT CURRENT_SETTING('search_path', true)
SELECT CURRENT_SETTING('role', true)
GO

0 comments on commit 359fa3a

Please sign in to comment.