Skip to content

Commit

Permalink
Support well known types 42 3 x (#3158)
Browse files Browse the repository at this point in the history
* fix Issue # 3145 boolean types not handled in SimpleQuery mode (#3146)

* handle all well known types in SimpleQuery mode and change else if to switch

* increment version to 42.3.10

* fix tests for v16+ versions
  • Loading branch information
davecramer committed Mar 13, 2024
1 parent 56d221c commit b032693
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin.parallel.tasks.in.project=true
# This is version for PgJdbc itself
# Note: it should not include "-SNAPSHOT" as it is automatically added by build.gradle.kts
# Release version can be generated by using -Prelease or -Prc=<int> arguments
pgjdbc.version=42.3.9
pgjdbc.version=42.3.10

# The options below configures the use of local clone (e.g. testing development versions)
# You can pass un-comment it, or pass option -PlocalReleasePlugins, or -PlocalReleasePlugins=<path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,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
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ public void testCustomArrayTypeInfo() throws SQLException {
assertTrue(res.next());
assertEquals("__custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("___custom", res.getString("TYPE_NAME"));
}
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v16)) {
assertEquals("__custom_1", res.getString("TYPE_NAME"));
} else {
assertEquals("___custom", res.getString("TYPE_NAME"));
} }
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3)) {
con.createArrayOf("custom", new Object[]{});
res = dbmd.getColumns(null, null, "customtable", null);
Expand All @@ -229,7 +232,11 @@ public void testCustomArrayTypeInfo() throws SQLException {
assertTrue(res.next());
assertEquals("__custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("___custom", res.getString("TYPE_NAME"));
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v16)) {
assertEquals("__custom_1", res.getString("TYPE_NAME"));
} else {
assertEquals("___custom", res.getString("TYPE_NAME"));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.postgresql.core.ServerVersion;
import org.postgresql.core.TypeInfo;
import org.postgresql.jdbc.PgConnection;
import org.postgresql.test.TestUtil;
Expand Down Expand Up @@ -102,7 +103,11 @@ public void testGetCorrectSQLTypeForShadowedTypes() throws Exception {
assertTrue(rs.next());
assertEquals("c", rs.getString("COLUMN_NAME"));
// = array of TYPE test_enum AS ENUM ('value')
assertEquals("Correctly detects shadowed array type name","___test_enum", rs.getString("TYPE_NAME"));
if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v16)) {
assertEquals("_test_enum_1", rs.getString("TYPE_NAME"), "Correctly detects shadowed array type name");
} else {
assertEquals("___test_enum", rs.getString("TYPE_NAME"), "Correctly detects shadowed array type name");
}
assertEquals("Correctly detects type of shadowed name", Types.ARRAY, rs.getInt("DATA_TYPE"));

assertFalse(rs.next());
Expand Down
Original file line number Diff line number Diff line change
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 b032693

Please sign in to comment.