Skip to content

Commit

Permalink
fix: make enum, json, and jsonb array result classes to be the same a…
Browse files Browse the repository at this point in the history
…s 42.2.14 and earlier

enum[] => String[]
jsonb[] => String[]
json[] => PGobject[]

fixes pgjdbc#1876
  • Loading branch information
vlsi authored and davecramer committed Nov 16, 2020
1 parent fd9d083 commit 3704867
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Added

### Fixed
- Handle nulls when the following clasess are used: PGbox, PGcircle, PGline, PGlseg, PGpath, PGpoint, PGpolygon, and PGmoney.
- Avoid NullPointerException when receiving PGbox, PGcircle, PGline, PGlseg, PGpath, PGpoint, PGpolygon, and PGmoney.
- The driver returns enum and jsonb arrays elements as String objects (like in 42.2.14 and earlier versions) [PR 1879](https://github.com/pgjdbc/pgjdbc/pull/1879).

## [42.2.16] (2020-08-20)
### Known issues
- The driver returns enum and jsonb arrays elements are returned as PGobject instances (fixed in 42.2.17)

### Fixed
- - Arrays sent in binary format are now sent as 1 based. This was a regression for multi-dimensional arrays as well as text/varchar, oid and bytea arrays.
- Arrays sent in binary format are now sent as 1 based. This was a regression for multi-dimensional arrays as well as text/varchar, oid and bytea arrays.
Since 42.2.0 single dimensional arrays were stored 0 based. They are now sent 1 based which is the SQL standard, and the default
for Postgres when sent as strings such as '{1,2,3}'. Fixes [issue 1860](https://github.com/pgjdbc/pgjdbc/issues/1860) in [PR 1863](https://github.com/pgjdbc/pgjdbc/pull/1863).

## [42.2.15] (2020-08-14)
### Known issues
- The driver returns enum and jsonb arrays elements are returned as PGobject instances (fixed in 42.2.17)

### Changed
- Rename source distribution archive to `postgresql-$version-jdbc-src.tar.gz`, and add top-level archive folder [ba017507](https://github.com/pgjdbc/pgjdbc/commit/ba0175072ee9c751c1496d2fe170f4af7256f1a5)
- Add the ability to connect with a GSSAPI encrypted connection. As of PostgreSQL version 12 GSSAPI encrypted connections
Expand Down
2 changes: 0 additions & 2 deletions docs/_posts/2020-01-30-42.2.10-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ version: 42.2.10
---
**Notable changes**


## [42.2.10] (2020-01-30)
### Changed
- (!) Regression: remove receiving EOF from backend after cancel [PR 1641](https://github.com/pgjdbc/pgjdbc/pull/1252). The regression is that the subsequent query might receive the cancel signal.

Expand Down
5 changes: 0 additions & 5 deletions docs/_posts/2020-03-31-42.2.12-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ version: 42.2.12
This change introduced a breaking change which will be moved to 42.3.0
- reverted [PR 1719](https://github.com/pgjdbc/pgjdbc/pull/1719) add support for full names of data types (#1719)

### Added

### Fixed


<!--more-->

**Commits by author**
Expand Down
11 changes: 0 additions & 11 deletions docs/_posts/2020-06-04-42.2.13-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,12 @@ version: 42.2.13
---
**Notable changes**

### Changed

### Added

### Fixed

## [42.2.13] (2020-06-04)

**Notable Changes**
The primary reason to release this version and to continue the 42.2.x branch is for CVE-2020-13692.
Reported by David Dworken this is an XXE and more information can be found [here](https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html)
Sehrope Sarkuni reworked the XML parsing to provide a solution in commit 14b62aca4
The build system has been changed to Gradle thanks to Vladimir [PR 1627](https://github.com/pgjdbc/pgjdbc/pull/1627)
Regression: com.github.waffle:waffle-jna, org.osgi:org.osgi.core, org.osgi:org.osgi.enterprise dependencies are listed as non-optional [issue 1975](https://github.com/pgjdbc/pgjdbc/issues/1795).

### Changed

### Added
- jre-6 was added back to allow us to release fixes for all artifacts in the 42.2.x branch [PR 1787](https://github.com/pgjdbc/pgjdbc/pull/1787)

Expand Down
3 changes: 3 additions & 0 deletions docs/_posts/2020-08-14-42.2.15-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ version: 42.2.15
---
**Notable changes**

### Known issues
- The driver returns enum and jsonb arrays elements are returned as PGobject instances (fixed in 42.2.17)

### Changed
- Rename source distribution archive to `postgresql-$version-jdbc-src.tar.gz`, and add top-level archive folder [ba017507](https://github.com/pgjdbc/pgjdbc/commit/ba0175072ee9c751c1496d2fe170f4af7256f1a5)
- Add the ability to connect with a GSSAPI encrypted connection. As of PostgreSQL version 12 GSSAPI encrypted connections
Expand Down
3 changes: 2 additions & 1 deletion docs/_posts/2020-08-20-42.2.16-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ version: 42.2.16
---
**Notable changes**

## [42.2.16] (2020-08-20)
### Known issues
- The driver returns enum and jsonb arrays elements are returned as PGobject instances (fixed in 42.2.17)

### Fixed
- Arrays sent in binary format are now sent as 1 based. This was a regression for multi-dimensional arrays as well as text/varchar, oid and bytea arrays.
Expand Down
1 change: 1 addition & 0 deletions pgjdbc/src/main/java/org/postgresql/core/Oid.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class Oid {
public static final int POINT = 600;
public static final int POINT_ARRAY = 1017;
public static final int BOX = 603;
public static final int JSONB = 3802;
public static final int JSONB_ARRAY = 3807;
public static final int JSON = 114;
public static final int JSON_ARRAY = 199;
Expand Down
12 changes: 11 additions & 1 deletion pgjdbc/src/main/java/org/postgresql/jdbc/ArrayDecoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.ByteOrder;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -374,13 +375,16 @@ Object parseValue(String stringVal, BaseConnection connection) throws SQLExcepti
OID_TO_DECODER.put(Oid.FLOAT4, FLOAT_OBJ_ARRAY);
OID_TO_DECODER.put(Oid.TEXT, STRING_ARRAY);
OID_TO_DECODER.put(Oid.VARCHAR, STRING_ARRAY);
// 42.2.x decodes jsonb array as String rather than PGobject
OID_TO_DECODER.put(Oid.JSONB, STRING_ONLY_DECODER);
OID_TO_DECODER.put(Oid.BIT, BOOLEAN_OBJ_ARRAY);
OID_TO_DECODER.put(Oid.BOOL, BOOLEAN_OBJ_ARRAY);
OID_TO_DECODER.put(Oid.BYTEA, BYTE_ARRAY_ARRAY);
OID_TO_DECODER.put(Oid.NUMERIC, BIG_DECIMAL_STRING_DECODER);
OID_TO_DECODER.put(Oid.BPCHAR, STRING_ONLY_DECODER);
OID_TO_DECODER.put(Oid.CHAR, STRING_ONLY_DECODER);
OID_TO_DECODER.put(Oid.JSON, STRING_ONLY_DECODER);
// 42.2.x decodes json array as PGobject rather than String
// OID_TO_DECODER.put(Oid.JSON, STRING_ONLY_DECODER);
OID_TO_DECODER.put(Oid.DATE, DATE_DECODER);
OID_TO_DECODER.put(Oid.TIME, TIME_DECODER);
OID_TO_DECODER.put(Oid.TIMETZ, TIME_DECODER);
Expand Down Expand Up @@ -471,6 +475,12 @@ Object parseValue(String stringVal, BaseConnection connection) throws SQLExcepti
throw org.postgresql.Driver.notImplemented(PgArray.class, "readArray(data,oid)");
}

// 42.2.x should return enums as strings
int type = connection.getTypeInfo().getSQLType(typeName);
if (type == Types.CHAR || type == Types.VARCHAR) {
return (ArrayDecoder<A>) STRING_ONLY_DECODER;
}

return (ArrayDecoder<A>) new MappedTypeObjectArrayDecoder(typeName);
}

Expand Down

0 comments on commit 3704867

Please sign in to comment.