Skip to content

Commit 818953a

Browse files
authored
fix Issue # 3145 boolean types not handled in SimpleQuery mode (#3146)
* 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
1 parent 0e8ab63 commit 818953a

2 files changed

Lines changed: 63 additions & 17 deletions

File tree

pgjdbc/src/main/java/org/postgresql/core/v3/SimpleParameterList.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,57 @@ public String toString(@Positive int index, boolean standardConformingStrings) {
317317
}
318318
} else {
319319
textValue = paramValue.toString();
320-
int paramType = paramTypes[index];
321-
if (paramType == Oid.TIMESTAMP) {
322-
type = "timestamp";
323-
} else if (paramType == Oid.TIMESTAMPTZ) {
324-
type = "timestamp with time zone";
325-
} else if (paramType == Oid.TIME) {
326-
type = "time";
327-
} else if (paramType == Oid.TIMETZ) {
328-
type = "time with time zone";
329-
} else if (paramType == Oid.DATE) {
330-
type = "date";
331-
} else if (paramType == Oid.INTERVAL) {
332-
type = "interval";
333-
} else if (paramType == Oid.NUMERIC) {
334-
type = "numeric";
335-
} else {
336-
type = null;
320+
switch (paramTypes[index]) {
321+
case Oid.INT2:
322+
type = "int2";
323+
break;
324+
case Oid.INT4:
325+
type = "int4";
326+
break;
327+
case Oid.INT8:
328+
type = "int8";
329+
break;
330+
case Oid.FLOAT4:
331+
type = "real";
332+
break;
333+
case Oid.FLOAT8:
334+
type = "double precision";
335+
break;
336+
case Oid.TIMESTAMP:
337+
type = "timestamp";
338+
break;
339+
case Oid.TIMESTAMPTZ:
340+
type = "timestamp with time zone";
341+
break;
342+
case Oid.TIME:
343+
type = "time";
344+
break;
345+
case Oid.TIMETZ:
346+
type = "time with time zone";
347+
break;
348+
case Oid.DATE:
349+
type = "date";
350+
break;
351+
case Oid.INTERVAL:
352+
type = "interval";
353+
break;
354+
case Oid.NUMERIC:
355+
type = "numeric";
356+
break;
357+
case Oid.UUID:
358+
type = "uuid";
359+
break;
360+
case Oid.BOOL:
361+
type = "boolean";
362+
break;
363+
case Oid.BOX:
364+
type = "box";
365+
break;
366+
case Oid.POINT:
367+
type = "point";
368+
break;
369+
default:
370+
type = null;
337371
}
338372
}
339373
return quoteAndCast(textValue, type, standardConformingStrings);

pgjdbc/src/test/java/org/postgresql/test/jdbc42/PreparedStatementTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ public void testSetNumber() throws SQLException {
5454
Assert.assertEquals(new BigDecimal("3.2"), d);
5555
}
5656

57+
@Test
58+
public void testSetBoolean() throws SQLException {
59+
try (PreparedStatement ps = con.prepareStatement("select false union select (select ?)")) {
60+
ps.setBoolean(1, true);
61+
62+
try (ResultSet rs = ps.executeQuery()) {
63+
assert (rs.next());
64+
rs.getBoolean(1);
65+
}
66+
}
67+
}
68+
5769
@Test
5870
public void testTimestampTzSetNull() throws SQLException {
5971
PreparedStatement pstmt = con.prepareStatement("INSERT INTO timestamptztable (tstz) VALUES (?)");

0 commit comments

Comments
 (0)