diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakePreparedStatementV1.java b/src/main/java/net/snowflake/client/jdbc/SnowflakePreparedStatementV1.java index aba023e4e..5be0e53b1 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakePreparedStatementV1.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakePreparedStatementV1.java @@ -966,4 +966,8 @@ public void resultSetMetadataHandler(SFBaseResultSet resultSet) throws SQLExcept alreadyDescribed = true; } } + + public String toString() { + return (this.sql != null) ? this.sql + " - Query ID: " + this.getQueryID() : super.toString(); + } } diff --git a/src/test/java/net/snowflake/client/jdbc/PreparedStatement2LatestIT.java b/src/test/java/net/snowflake/client/jdbc/PreparedStatement2LatestIT.java index ba3d4617a..a034aed0c 100644 --- a/src/test/java/net/snowflake/client/jdbc/PreparedStatement2LatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PreparedStatement2LatestIT.java @@ -354,4 +354,24 @@ public void testConsecutiveBatchInsertError() throws SQLException { assertTrue(prepStatement.unwrap(SnowflakePreparedStatementV1.class).isArrayBindSupported()); } } + + @Test + public void testToString() throws SQLException { + try (Connection connection = init()) { + PreparedStatement prepStatement = + connection.prepareStatement("select current_version() --testing toString()"); + + // Query ID is going to be null since we didn't execute the statement yet + assertEquals( + "select current_version() --testing toString() - Query ID: null", + prepStatement.toString()); + + prepStatement.executeQuery(); + assertTrue( + prepStatement + .toString() + .matches( + "select current_version\\(\\) --testing toString\\(\\) - Query ID: (\\d|\\w)+(-(\\d|\\w)+)+$")); + } + } }