diff --git a/src/main/java/net/snowflake/client/core/SFSession.java b/src/main/java/net/snowflake/client/core/SFSession.java index 428bda118..2279a4c85 100644 --- a/src/main/java/net/snowflake/client/core/SFSession.java +++ b/src/main/java/net/snowflake/client/core/SFSession.java @@ -241,12 +241,17 @@ else if (ex instanceof SFException) { else if (isAnError(result)) { result.setErrorCode(ErrorCode.INTERNAL_ERROR.getMessageCode()); result.setErrorMessage("no_error_code_from_server"); + } else if (!isAnError(result)) { + result.setErrorCode(0); + result.setErrorMessage("No error reported"); } // if an error message has been provided, set appropriate error message. // This should override the default error message displayed when there is // an error with no code. if (!Strings.isNullOrEmpty(errorMessage) && !errorMessage.equalsIgnoreCase("null")) { result.setErrorMessage(errorMessage); + } else { + result.setErrorMessage("No error reported"); } return result; } diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java index fa50e0bbc..f5548ab8f 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java @@ -271,6 +271,37 @@ public void testAsyncAndSynchronousQueries() throws SQLException { con.close(); } + /** + * Tests that error message and error code are reset after an error + * + * @throws SQLException + * @throws InterruptedException + */ + @Test + public void testQueryStatusErrorMessageAndErrorCode() throws SQLException, InterruptedException { + // open connection and run asynchronous query + Connection con = getConnection(); + Statement statement = con.createStatement(); + statement.execute("create or replace table testTable(colA string, colB boolean)"); + statement.execute("insert into testTable values ('test', true)"); + ResultSet rs1 = + statement.unwrap(SnowflakeStatement.class).executeAsyncQuery("select * from testTable"); + QueryStatus status = rs1.unwrap(SnowflakeResultSet.class).getStatus(); + // Set the error message and error code so we can confirm they are reset when getStatus() is + // called. + status.setErrorMessage(QueryStatus.FAILED_WITH_ERROR.toString()); + status.setErrorCode(2003); + Thread.sleep(300); + status = rs1.unwrap(SnowflakeResultSet.class).getStatus(); + // Assert status of query is a success + assertEquals(QueryStatus.SUCCESS, status); + assertEquals("No error reported", status.getErrorMessage()); + assertEquals(0, status.getErrorCode()); + statement.execute("drop table if exists testTable"); + statement.close(); + con.close(); + } + @Test public void testPreparedStatementAsyncQuery() throws SQLException { Connection con = getConnection();