snowflake-jdbc
snowflake-jdbc copied to clipboard
SNOW-558640: Executing USE ROLE clears connection catalog/schema
Executing USE ROLE
clears the connection default catalog but current_database()
still returns the default catalog/database.
Is this intended behavior?
Example to reproduce behavior:
Connection connection = driver.connect("jdbc:snowflake://<Accountname>:443/?db=demo", properties);
connection.getCatalog(); // returns "demo"
ResultSet rs = connection.prepareStatement("select current_database()").executeQuery();
rs.next();
rs.getString(1); // returns "demo"
connection.prepareStatement("USE ROLE test").executeQuery();
connection.getCatalog(); // returns null
ResultSet rs = connection.prepareStatement("select current_database()").executeQuery();
rs.next();
rs.getString(1); // returns "demo"
The reason is the json response from snowflake has finalDatabaseName
set to null and then the connection catalog is set to null:
https://github.com/snowflakedb/snowflake-jdbc/blob/master/src/main/java/net/snowflake/client/jdbc/SnowflakeResultSetSerializableV1.java#L496-L497
A similar problem also occurs when setting the connection default schema and then executing USE ROLE.
@sfc-gh-wfateem is this fixed in any newer versions? I don't see a mention in release notes or a related commit.
The problem I am running into is that as soon as I have executed USE ROLE
on a connection the result of connection.getCatalog
becomes incorrect and I have to find alternative ways to preserve and restore correct catalog name in all places where connection is used.
Which either means injecting correct catalog name into SQL statements or changing the parameters passed to JdbcMetaData methods like getTables
.
Please check this with upcoming March 2023 release. We fix similar issue.
Thank you! Looks like it was fixed.