Skip to content

Commit

Permalink
fix Issue # 3145 boolean types not handled in SimpleQuery mode (#3146)
Browse files Browse the repository at this point in the history
* make sure we handle boolean types in simple query mode

* support uuid as well

* handle all well known types in text mode and change else if to switch
  • Loading branch information
davecramer committed Mar 1, 2024
1 parent 0e8ab63 commit 818953a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
Expand Up @@ -317,23 +317,57 @@ public String toString(@Positive int index, boolean standardConformingStrings) {
}
} else {
textValue = paramValue.toString();
int paramType = paramTypes[index];
if (paramType == Oid.TIMESTAMP) {
type = "timestamp";
} else if (paramType == Oid.TIMESTAMPTZ) {
type = "timestamp with time zone";
} else if (paramType == Oid.TIME) {
type = "time";
} else if (paramType == Oid.TIMETZ) {
type = "time with time zone";
} else if (paramType == Oid.DATE) {
type = "date";
} else if (paramType == Oid.INTERVAL) {
type = "interval";
} else if (paramType == Oid.NUMERIC) {
type = "numeric";
} else {
type = null;
switch (paramTypes[index]) {
case Oid.INT2:
type = "int2";
break;
case Oid.INT4:
type = "int4";
break;
case Oid.INT8:
type = "int8";
break;
case Oid.FLOAT4:
type = "real";
break;
case Oid.FLOAT8:
type = "double precision";
break;
case Oid.TIMESTAMP:
type = "timestamp";
break;
case Oid.TIMESTAMPTZ:
type = "timestamp with time zone";
break;
case Oid.TIME:
type = "time";
break;
case Oid.TIMETZ:
type = "time with time zone";
break;
case Oid.DATE:
type = "date";
break;
case Oid.INTERVAL:
type = "interval";
break;
case Oid.NUMERIC:
type = "numeric";
break;
case Oid.UUID:
type = "uuid";
break;
case Oid.BOOL:
type = "boolean";
break;
case Oid.BOX:
type = "box";
break;
case Oid.POINT:
type = "point";
break;
default:
type = null;
}
}
return quoteAndCast(textValue, type, standardConformingStrings);
Expand Down
Expand Up @@ -54,6 +54,18 @@ public void testSetNumber() throws SQLException {
Assert.assertEquals(new BigDecimal("3.2"), d);
}

@Test
public void testSetBoolean() throws SQLException {
try (PreparedStatement ps = con.prepareStatement("select false union select (select ?)")) {
ps.setBoolean(1, true);

try (ResultSet rs = ps.executeQuery()) {
assert (rs.next());
rs.getBoolean(1);
}
}
}

@Test
public void testTimestampTzSetNull() throws SQLException {
PreparedStatement pstmt = con.prepareStatement("INSERT INTO timestamptztable (tstz) VALUES (?)");
Expand Down

0 comments on commit 818953a

Please sign in to comment.