Skip to content
Browse files

feat: support HSTORE in PgPreparedStatement#setObject(int, java.lang.…

…Object, int, int)

setObject(int, java.lang.Object) did support hstore, so setObject(int, Object, int, int) was enhanced as well to support hstore
  • Loading branch information
dosimeta authored and vlsi committed Jul 5, 2016
1 parent 7311b4e commit 785d0c75b77ed2cb59d319eb18f9d784155a068c
@@ -738,6 +738,8 @@ public void setObject(int parameterIndex, Object in, int targetSqlType, int scal
case Types.OTHER:
if (in instanceof PGobject) {
setPGobject(parameterIndex, (PGobject) in);
} else if (in instanceof Map) {
setMap(parameterIndex, (Map<?, ?>) in);
} else {
bindString(parameterIndex, in.toString(), Oid.UNSPECIFIED);
@@ -16,6 +16,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -74,6 +75,16 @@ public void testHStoreSend() throws SQLException {
assertEquals("\"a\"=>\"1\"", rs.getString(1));

public void testHStoreUsingPSSetObject4() throws SQLException {
Map<String, Integer> correct = Collections.singletonMap("a", new Integer(1));
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::text");
pstmt.setObject(1, correct, Types.OTHER, -1);
ResultSet rs = pstmt.executeQuery();
assertEquals(String.class.getName(), rs.getMetaData().getColumnClassName(1));
assertEquals("\"a\"=>\"1\"", rs.getString(1));

public void testHStoreSendEscaped() throws SQLException {
Map<String, String> correct = Collections.singletonMap("a", "t'e\ns\"t");
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?");

0 comments on commit 785d0c7

Please sign in to comment.