Skip to content

Commit

Permalink
Merge pull request #939 from snowflakedb/addOptionToSetByteInSetObJec…
Browse files Browse the repository at this point in the history
…tForPreparedStatements

Add option to set byte[] in SnowflakePreparedStatement.setObject
  • Loading branch information
SimbaGithub authored May 5, 2022
2 parents dc13691 + 93b4e20 commit 716022e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ public void setObject(int parameterIndex, Object x) throws SQLException {
setTimestamp(parameterIndex, (Timestamp) x);
} else if (x instanceof Boolean) {
setBoolean(parameterIndex, (Boolean) x);
} else if (x instanceof byte[]) {
setBytes(parameterIndex, (byte[]) x);
} else {
throw new SnowflakeSQLLoggedException(
connection.getSFBaseSession(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,22 @@ public void testExecuteEmptyBatch() throws SQLException {
}
}
}

/**
* Tests that VARBINARY columns can be set in setObject() method using byte[]
*
* @throws SQLException
*/
@Test
public void testSetObjectMethodWithVarbinaryColumn() throws SQLException {
try (Connection connection = init()) {
connection.createStatement().execute("create or replace table test_binary(b VARBINARY)");

try (PreparedStatement prepStatement =
connection.prepareStatement("insert into test_binary(b) values (?)")) {
prepStatement.setObject(1, "HELLO WORLD".getBytes());
prepStatement.execute(); // shouldn't raise an error.
}
}
}
}

0 comments on commit 716022e

Please sign in to comment.