Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre release42.2.17 1 #1913

Closed
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added

### Fixed

## [42.2.17]
### Changed
- Change default of gssEncMode to ALLOW. PostgreSQL can deal with PREFER but there are cloud providers that did not implement the protocol properly
### Added
- Add smallserial metadata (#899)

### Fixed
- 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).
- PgTokenizer was ignoring last empty token (#1882)
- Remove osgi from karaf fixes Issue #1891 (#1902)

## [42.2.16] (2020-08-20)
### Known issues
Expand Down
63 changes: 63 additions & 0 deletions docs/_posts/2020-10-02-42.2.17-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: PostgreSQL JDBC Driver 42.2.17 Released
date: 2020-10-02 14:24:57 +0000
categories:
- new_release
version: 42.2.17
---
**Notable changes**

### Changed

### Added

### Fixed

## [42.2.17]
### Changed
- Change default of gssEncMode to ALLOW. PostgreSQL can deal with PREFER but there are cloud providers that did not implement the protocol properly
### Added
- Add smallserial metadata (#899)

### Fixed
- 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).
- PgTokenizer was ignoring last empty token (#1882)
- Remove osgi from karaf fixes Issue #1891 (#1902)


<!--more-->

**Commits by author**

Dave Cramer (5):

* fix: PgTokenizer was ignoring last empty token [PR 1882](https://github.com/pgjdbc/pgjdbc/pull/1882) [a6e83342](https://github.com/pgjdbc/pgjdbc/commit/a6e833429303acf330b9ff512df55e1c3c158ee2)
* fix checkstyle [PR 1888](https://github.com/pgjdbc/pgjdbc/pull/1888) [70b02c55](https://github.com/pgjdbc/pgjdbc/commit/70b02c55233bec6ea87286b4fb80ac60a0ebd76f)
* fix: handle smallserial correctly fixes [PR 1897](https://github.com/pgjdbc/pgjdbc/pull/1897) (#1899) [d4a4b2d6](https://github.com/pgjdbc/pgjdbc/commit/d4a4b2d643547e89fc349847d8d0c098108270ab)
* fix:remove osgi from karaf fixes Issue [PR 1891](https://github.com/pgjdbc/pgjdbc/pull/1891) (#1902) [0c2858e9](https://github.com/pgjdbc/pgjdbc/commit/0c2858e9cabb1209c2b30cf03c07a30b8051cf4c)
* Change default of gssEncMode to ALLOW. PostgreSQL can deal with PREFER but there are cloud providers that did not implement the protocol properly [14c4173c](https://github.com/pgjdbc/pgjdbc/commit/14c4173ca6719a8dea8539621583d785bbd8f632)

Jorge Solorzano (1):

* feat: add smallserial metadata [PR 899](https://github.com/pgjdbc/pgjdbc/pull/899) [05403bd0](https://github.com/pgjdbc/pgjdbc/commit/05403bd02ed40e4f029f19800b32af9f96637e34)

Vladimir Sitnikov (8):

* fix: handle nulls when the following clasess are used: PGbox, PGcircle, PGline, PGlseg, PGpath, PGpoint, PGpolygon, and PGmoney [c745f4e5](https://github.com/pgjdbc/pgjdbc/commit/c745f4e549b119b8332ef48bbc8b8525ccba0f21)
* chore: fix compileJava7 and compileJava6 [0308ffca](https://github.com/pgjdbc/pgjdbc/commit/0308ffcafa49271d1dabd001404b955c5e8bbe28)
* chore: run GitHub actions when branch name has slash [433817d6](https://github.com/pgjdbc/pgjdbc/commit/433817d606c42e897ee4b37baf7b50eda5ab3356)
* chore: seed build cache only when credentials exist (==skip on forks) [eec708a8](https://github.com/pgjdbc/pgjdbc/commit/eec708a80ad17f5a17bba5cdbcdcb640b094a965)
* test: add GitHub CI for testing source distribution [44d0923f](https://github.com/pgjdbc/pgjdbc/commit/44d0923fa85e159ac937277767b4dfe2a67df28c)
* test: add tests for enum, json, and jsonb array [1bec4022](https://github.com/pgjdbc/pgjdbc/commit/1bec402208eef17fd81f5dd7cca1d1a36e1466da)
* fix: make enum, json, and jsonb array result classes to be the same as 42.2.14 and earlier [PR 1876](https://github.com/pgjdbc/pgjdbc/pull/1876) [41855018](https://github.com/pgjdbc/pgjdbc/commit/41855018a0371ea6c36d1c88e3a33402f44f53eb)
* fix: avoid removal type annotations on "this" so the source archive is buildable [832bf21c](https://github.com/pgjdbc/pgjdbc/commit/832bf21c3ac37691dc71f6ee6bc1e3da34c7d746)

<a name="contributors_{{ page.version }}"></a>
### Contributors to this release

We thank the following people for their contributions to this release.

[Dave Cramer](davec@postgresintl.com)
[Jorge Solorzano](https://github.com/jorsol)
[Vladimir Sitnikov](https://github.com/vlsi)
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.2.16
pgjdbc.version=42.2.17

# 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
10 changes: 1 addition & 9 deletions pgjdbc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ dependencies {
shaded("com.ongres.scram:client")

implementation("org.checkerframework:checker-qual")

// https://github.com/lburgazzoli/gradle-karaf-plugin/issues/75
karafFeatures(platform(project(":bom")))
karafFeatures("org.osgi:org.osgi.core:${"org.osgi.core".v}")
karafFeatures("org.osgi:org.osgi.enterprise:${"org.osgi.enterprise".v}")

testImplementation("se.jiderhamn:classloader-leak-test-framework")
}

Expand Down Expand Up @@ -256,17 +250,15 @@ val hiddenAnnotation = Regex(
"GuardedBy|UnderInitialization|" +
"DefaultQualifier)(?:\\([^)]*\\))?")
val hiddenImports = Regex("import org.checkerframework")
val thisReferences = Regex("""\*/\s+(\w+\s+this\b,?)""")

val removeTypeAnnotations by tasks.registering(Sync::class) {
destinationDir = withoutAnnotations
inputs.property("regexpsUpdatedOn", "2020-08-29")
inputs.property("regexpsUpdatedOn", "2020-08-25")
from(projectDir) {
filteringCharset = `java.nio.charset`.StandardCharsets.UTF_8.name()
filter { x: String ->
x.replace(hiddenAnnotation, "/* $0 */")
.replace(hiddenImports, "// $0")
.replace(thisReferences, "*/ /* $1 */")
}
include("src/**")
}
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/jdbc/GSSEncMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static GSSEncMode of(Properties info) throws PSQLException {
String gssEncMode = PGProperty.GSS_ENC_MODE.get(info);
// If gssEncMode is not set, fallback to prefer
if (gssEncMode == null) {
return PREFER;
return ALLOW;
}

for (GSSEncMode mode : VALUES) {
Expand Down
24 changes: 14 additions & 10 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1604,15 +1604,13 @@ public ResultSet getColumns(@Nullable String catalog, @Nullable String schemaPat

String defval = rs.getString("adsrc");

if (defval != null) {
if (defval != null && defval.contains("nextval(") ) {
if ("int4".equals(pgType)) {
if (defval.contains("nextval(")) {
tuple[5] = connection.encodeString("serial"); // Type name == serial
}
tuple[5] = connection.encodeString("serial"); // Type name == serial
} else if ("int8".equals(pgType)) {
if (defval.contains("nextval(")) {
tuple[5] = connection.encodeString("bigserial"); // Type name == bigserial
}
tuple[5] = connection.encodeString("bigserial"); // Type name == bigserial
} else if ("int2".equals(pgType) && connection.haveMinimumServerVersion(ServerVersion.v9_2)) {
tuple[5] = connection.encodeString("smallserial"); // Type name == smallserial
}
}
String identity = rs.getString("attidentity");
Expand Down Expand Up @@ -2374,19 +2372,25 @@ public ResultSet getTypeInfo() throws SQLException {
tuple[17] = b10; // everything is base 10
v.add(new Tuple(tuple));

// add pseudo-type serial, bigserial
if (typname.equals("int4")) {
// add pseudo-type serial, bigserial, smallserial
if ("int4".equals(typname)) {
byte[] @Nullable [] tuple1 = tuple.clone();

tuple1[0] = connection.encodeString("serial");
tuple1[11] = bt;
v.add(new Tuple(tuple1));
} else if (typname.equals("int8")) {
} else if ("int8".equals(typname)) {
byte[] @Nullable [] tuple1 = tuple.clone();

tuple1[0] = connection.encodeString("bigserial");
tuple1[11] = bt;
v.add(new Tuple(tuple1));
} else if ("int2".equals(typname) && connection.haveMinimumServerVersion(ServerVersion.v9_2)) {
byte[] @Nullable [] tuple1 = tuple.clone();

tuple1[0] = connection.encodeString("smallserial");
tuple1[11] = bt;
v.add(new Tuple(tuple1));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ public String getColumnTypeName(int column) throws SQLException {
return "serial";
} else if ("int8".equals(type)) {
return "bigserial";
} else if ("int2".equals(type) && connection.haveMinimumServerVersion(ServerVersion.v9_2)) {
return "smallserial";
}
}

Expand Down
9 changes: 7 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/util/PGtokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public int tokenize(String string, char delim) {
int s;
boolean skipChar = false;
boolean nestedDoubleQuote = false;

char c = (char)0;
for (p = 0, s = 0; p < string.length(); p++) {
char c = string.charAt(p);
c = string.charAt(p);

// increase nesting if an open character is found
if (c == '(' || c == '[' || c == '<' || (!nestedDoubleQuote && !skipChar && c == '"')) {
Expand Down Expand Up @@ -94,6 +94,11 @@ public int tokenize(String string, char delim) {
tokens.add(string.substring(s));
}

// check for last token empty
if ( s == string.length() && c == delim) {
tokens.add("");
}

return tokens.size();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,15 @@ public void testSerialColumns() throws SQLException {
assertEquals(rownum + 1, rs.getInt("ORDINAL_POSITION"));
if (rownum == 0) {
assertEquals("int4", rs.getString("TYPE_NAME"));

} else if (rownum == 1) {
assertEquals("serial", rs.getString("TYPE_NAME"));
assertTrue(rs.getBoolean("IS_AUTOINCREMENT"));
} else if (rownum == 2) {
assertEquals("bigserial", rs.getString("TYPE_NAME"));
assertTrue(rs.getBoolean("IS_AUTOINCREMENT"));
}

rownum++;
}
assertEquals(3, rownum);
Expand Down Expand Up @@ -1484,4 +1488,56 @@ public void testFunctionColumns() throws SQLException {

rs.close();
}

@Test
public void testSmallSerialColumns() throws SQLException {
org.junit.Assume.assumeTrue(TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_2));
TestUtil.createTable(con, "smallserial_test", "a smallserial");

DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getColumns(null, null, "smallserial_test", "a");
assertTrue(rs.next());
assertEquals("smallserial_test", rs.getString("TABLE_NAME"));
assertEquals("a", rs.getString("COLUMN_NAME"));
assertEquals(Types.SMALLINT, rs.getInt("DATA_TYPE"));
assertEquals("smallserial", rs.getString("TYPE_NAME"));
assertTrue(rs.getBoolean("IS_AUTOINCREMENT"));
assertEquals("nextval('smallserial_test_a_seq'::regclass)", rs.getString("COLUMN_DEF"));
assertFalse(rs.next());
rs.close();

TestUtil.dropTable(con, "smallserial_test");
}

@Test
public void testSmallSerialSequenceLikeColumns() throws SQLException {
Statement stmt = con.createStatement();
// This is the equivalent of the smallserial, not the actual smallserial
stmt.execute("CREATE SEQUENCE smallserial_test_a_seq;\n"
+ "CREATE TABLE smallserial_test (\n"
+ " a smallint NOT NULL DEFAULT nextval('smallserial_test_a_seq')\n"
+ ");\n"
+ "ALTER SEQUENCE smallserial_test_a_seq OWNED BY smallserial_test.a;");

DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getColumns(null, null, "smallserial_test", "a");
assertTrue(rs.next());
assertEquals("smallserial_test", rs.getString("TABLE_NAME"));
assertEquals("a", rs.getString("COLUMN_NAME"));
assertEquals(Types.SMALLINT, rs.getInt("DATA_TYPE"));
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_2)) {
// in Pg 9.2+ it behaves like smallserial
assertEquals("smallserial", rs.getString("TYPE_NAME"));
} else {
assertEquals("int2", rs.getString("TYPE_NAME"));
}
assertTrue(rs.getBoolean("IS_AUTOINCREMENT"));
assertEquals("nextval('smallserial_test_a_seq'::regclass)", rs.getString("COLUMN_DEF"));
assertFalse(rs.next());
rs.close();

stmt.execute("DROP TABLE smallserial_test");
stmt.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,50 @@ private void assumePreparedStatementMetadataSupported() {
preferQueryMode.compareTo(PreferQueryMode.EXTENDED_FOR_PREPARED) >= 0);
}

@Test
public void testSmallSerialColumns() throws SQLException {
org.junit.Assume.assumeTrue(TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_2));
TestUtil.createTable(con, "smallserial_test", "a smallserial");

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a FROM smallserial_test");
ResultSetMetaData rsmd = rs.getMetaData();
assertTrue(rsmd.isAutoIncrement(1));
assertEquals("smallserial_test", rsmd.getTableName(1));
assertEquals("a", rsmd.getColumnName(1));
assertEquals(Types.SMALLINT, rsmd.getColumnType(1));
assertEquals("smallserial", rsmd.getColumnTypeName(1));
rs.close();

TestUtil.dropTable(con, "smallserial_test");
}

@Test
public void testSmallSerialSequenceLikeColumns() throws SQLException {
Statement stmt = con.createStatement();
// This is the equivalent of the smallserial, not the actual smallserial
stmt.execute("CREATE SEQUENCE smallserial_test_a_seq;\n"
+ "CREATE TABLE smallserial_test (\n"
+ " a smallint NOT NULL DEFAULT nextval('smallserial_test_a_seq')\n"
+ ");\n"
+ "ALTER SEQUENCE smallserial_test_a_seq OWNED BY smallserial_test.a;");

ResultSet rs = stmt.executeQuery("SELECT a FROM smallserial_test");
ResultSetMetaData rsmd = rs.getMetaData();
assertTrue(rsmd.isAutoIncrement(1));
assertEquals("smallserial_test", rsmd.getTableName(1));
assertEquals("a", rsmd.getColumnName(1));
assertEquals(Types.SMALLINT, rsmd.getColumnType(1));
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_2)) {
// in Pg 9.2+ it behaves like smallserial
assertEquals("smallserial", rsmd.getColumnTypeName(1));
} else {
assertEquals("int2", rsmd.getColumnTypeName(1));
}
rs.close();

stmt.execute("DROP TABLE smallserial_test");
stmt.close();
}

}
43 changes: 43 additions & 0 deletions pgjdbc/src/test/java/org/postgresql/util/PGtokenizerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2017, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/

package org.postgresql.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

class PGtokenizerTest {

@Test
void tokenize() {
PGtokenizer pGtokenizer = new PGtokenizer("1,2EC1830300027,1,,",',');
assertEquals(5,pGtokenizer.getSize());

}

@Test
void removePara() {
String string = PGtokenizer.removePara("(1,2EC1830300027,1,,)");
Assert.assertEquals("1,2EC1830300027,1,,", string);
}

@Test
void removeBox() {
assertTrue(true);
}

@Test
void removeAngle() {
assertTrue(true);
}

@Test
void removeCurlyBrace() {
assertTrue(true);
}
}