[Git][java-team/libpostgresql-jdbc-java][master] 3 commits: New upstream version 42.2.22

Christoph Berg (@myon) gitlab at salsa.debian.org
Wed Jun 30 12:36:41 BST 2021



Christoph Berg pushed to branch master at Debian Java Maintainers / libpostgresql-jdbc-java


Commits:
1c509748 by Christoph Berg at 2021-06-30T13:35:12+02:00
New upstream version 42.2.22
- - - - -
73a8748e by Christoph Berg at 2021-06-30T13:35:17+02:00
Update upstream source from tag 'upstream/42.2.22'

Update to upstream version '42.2.22'
with Debian dir 30b6e972e6cdc8c6c8ce76c3daf950f1c0405cbc
- - - - -
07032436 by Christoph Berg at 2021-06-30T13:36:29+02:00
New upstream version 42.2.22.

- - - - -


11 changed files:

- debian/changelog
- pom.xml
- src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java
- src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java
- src/main/java/org/postgresql/jdbc/PgResultSet.java
- src/main/java/org/postgresql/util/DriverInfo.java
- src/main/java/org/postgresql/util/PSQLState.java
- src/main/resources/META-INF/MANIFEST.MF
- src/test/java/org/postgresql/test/jdbc2/CopyTest.java
- src/test/java/org/postgresql/test/jdbc2/UpdateableResultTest.java
- src/test/java/org/postgresql/test/jdbc4/DatabaseMetaDataTest.java


Changes:

=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+libpgjava (42.2.22-1) unstable; urgency=medium
+
+  * New upstream version 42.2.22.
+
+ -- Christoph Berg <myon at debian.org>  Wed, 30 Jun 2021 13:35:21 +0200
+
 libpgjava (42.2.20-1) unstable; urgency=medium
 
   * New upstream version 42.2.20.


=====================================
pom.xml
=====================================
@@ -10,7 +10,7 @@
     <artifactId>postgresql</artifactId>
     <packaging>jar</packaging>
     <name>PostgreSQL JDBC Driver - JDBC 4.2</name>
-    <version>42.2.20</version>
+    <version>42.2.22</version>
     <description>Java JDBC 4.2 (JRE 8+) driver for PostgreSQL database</description>
     <url>https://github.com/pgjdbc/pgjdbc</url>
 


=====================================
src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java
=====================================
@@ -291,7 +291,6 @@ public class QueryExecutorImpl extends QueryExecutorBase {
       LOGGER.log(Level.FINEST, "  simple execute, handler={0}, maxRows={1}, fetchSize={2}, flags={3}",
           new Object[]{handler, maxRows, fetchSize, flags});
     }
-
     if (parameters == null) {
       parameters = SimpleQuery.NO_PARAMETERS;
     }
@@ -2312,6 +2311,7 @@ public class QueryExecutorImpl extends QueryExecutorBase {
         }
 
         case 'N': // Notice Response
+          LOGGER.log(Level.FINEST, " <=BE Notice");
           SQLWarning warning = receiveNoticeResponse();
           handler.handleWarning(warning);
           break;
@@ -2369,7 +2369,6 @@ public class QueryExecutorImpl extends QueryExecutorBase {
             }
           }
           endQuery = true;
-
           // Reset the statement name of Parses that failed.
           while (!pendingParseQueue.isEmpty()) {
             SimpleQuery failedQuery = pendingParseQueue.removeFirst();


=====================================
src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java
=====================================
@@ -1051,9 +1051,6 @@ public class PgDatabaseMetaData implements DatabaseMetaData {
     }
     if (schemaPattern != null && !schemaPattern.isEmpty()) {
       sql += " AND n.nspname LIKE " + escapeQuotes(schemaPattern);
-    } else {
-      /* limit to current schema if no schema given */
-      sql += "and pg_function_is_visible(p.oid)";
     }
     if (procedureNamePattern != null && !procedureNamePattern.isEmpty()) {
       sql += " AND p.proname LIKE " + escapeQuotes(procedureNamePattern);
@@ -2797,9 +2794,6 @@ public class PgDatabaseMetaData implements DatabaseMetaData {
      */
     if (schemaPattern != null && !schemaPattern.isEmpty()) {
       sql += " AND n.nspname LIKE " + escapeQuotes(schemaPattern);
-    } else {
-      /* if no schema is provided then limit the search inside the search_path */
-      sql += "and pg_function_is_visible(p.oid)";
     }
     if (functionNamePattern != null && !functionNamePattern.isEmpty()) {
       sql += " AND p.proname LIKE " + escapeQuotes(functionNamePattern);


=====================================
src/main/java/org/postgresql/jdbc/PgResultSet.java
=====================================
@@ -1639,7 +1639,7 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS
     /*
     it is only updatable if the primary keys are available in the resultset
      */
-    updateable = (i == numPKcolumns);
+    updateable = (i == numPKcolumns) && (numPKcolumns > 0);
 
     connection.getLogger().log(Level.FINE, "checking primary key {0}", updateable);
 


=====================================
src/main/java/org/postgresql/util/DriverInfo.java
=====================================
@@ -16,13 +16,13 @@ public final class DriverInfo {
   // Driver name
   public static final String DRIVER_NAME = "PostgreSQL JDBC Driver";
   public static final String DRIVER_SHORT_NAME = "PgJDBC";
-  public static final String DRIVER_VERSION = "42.2.20";
+  public static final String DRIVER_VERSION = "42.2.22";
   public static final String DRIVER_FULL_NAME = DRIVER_NAME + " " + DRIVER_VERSION;
 
   // Driver version
   public static final int MAJOR_VERSION = 42;
   public static final int MINOR_VERSION = 2;
-  public static final int PATCH_VERSION = 20;
+  public static final int PATCH_VERSION = 22;
 
   // JDBC specification
   public static final String JDBC_VERSION = "4.2";


=====================================
src/main/java/org/postgresql/util/PSQLState.java
=====================================
@@ -105,6 +105,8 @@ public enum PSQLState {
   SYSTEM_ERROR("60000"),
   IO_ERROR("58030"),
 
+  ERROR_CODE_CRASH_SHUTDOWN("57P02"),
+
   UNEXPECTED_ERROR("99999");
 
   private final String state;


=====================================
src/main/resources/META-INF/MANIFEST.MF
=====================================
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Implementation-Title: PostgreSQL JDBC Driver
 Bundle-License: BSD-2-Clause
 Automatic-Module-Name: org.postgresql.jdbc
-Implementation-Version: 42.2.20
+Implementation-Version: 42.2.22
 Specification-Vendor: Oracle Corporation
 Specification-Title: JDBC
 Implementation-Vendor-Id: org.postgresql


=====================================
src/test/java/org/postgresql/test/jdbc2/CopyTest.java
=====================================
@@ -440,7 +440,8 @@ public class CopyTest {
     if (rollbackException == null) {
       fail("rollback should have thrown an exception");
     }
-    acceptIOCause(rollbackException);
+
+    assertTrue( rollbackException instanceof SQLException);
   }
 
   private static class Rollback extends Thread {


=====================================
src/test/java/org/postgresql/test/jdbc2/UpdateableResultTest.java
=====================================
@@ -46,6 +46,7 @@ public class UpdateableResultTest extends BaseTest4 {
     TestUtil.execute( "alter table compositepktable add primary key ( gen_id, dec_id )", con);
     TestUtil.createTable(con, "stream", "id int primary key, asi text, chr text, bin bytea");
     TestUtil.createTable(con, "multicol", "id1 int not null, id2 int not null, val text");
+    TestUtil.createTable(con, "nopkmulticol", "id1 int not null, id2 int not null, val text");
     TestUtil.createTable(con, "booltable", "id int not null primary key, b boolean default false");
     TestUtil.execute( "insert into booltable (id) values (1)", con);
 
@@ -65,6 +66,7 @@ public class UpdateableResultTest extends BaseTest4 {
     TestUtil.dropTable(con, "serialtable");
     TestUtil.dropTable(con, "compositepktable");
     TestUtil.dropTable(con, "stream");
+    TestUtil.dropTable(con, "nopkmulticol");
     TestUtil.dropTable(con, "booltable");
     super.tearDown();
   }
@@ -594,6 +596,23 @@ public class UpdateableResultTest extends BaseTest4 {
     }
   }
 
+  @Test
+  public void testMultiColumnUpdateWithoutPrimaryKey() throws Exception {
+    Statement st =
+        con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
+    ResultSet rs = st.executeQuery("select * from nopkmulticol");
+    try {
+      rs.moveToInsertRow();
+      fail("Move to insert row succeeded. It should not");
+    } catch (SQLException sqle) {
+      // Ensure we're reporting that the RS is not updatable.
+      assertEquals("24000", sqle.getSQLState());
+    } finally {
+      TestUtil.closeQuietly(rs);
+      TestUtil.closeQuietly(st);
+    }
+  }
+
   @Test
   public void testMultiColumnUpdate() throws Exception {
     Statement st =


=====================================
src/test/java/org/postgresql/test/jdbc4/DatabaseMetaDataTest.java
=====================================
@@ -7,6 +7,7 @@ package org.postgresql.test.jdbc4;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -18,6 +19,7 @@ import org.postgresql.test.SlowTests;
 import org.postgresql.test.TestUtil;
 
 import org.junit.After;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -108,125 +110,103 @@ public class DatabaseMetaDataTest {
   @Test
   public void testGetFunctionsInSchemaForFunctions() throws SQLException {
     DatabaseMetaData dbmd = conn.getMetaData();
-    ResultSet rs = dbmd.getFunctions("", "hasfunctions","");
-    int count = assertGetFunctionRS(rs);
-    assertThat( count, is(1));
 
-    Statement statement = conn.createStatement();
-    statement.execute("set search_path=hasfunctions");
-
-    rs = dbmd.getFunctions("", "","addfunction");
-    assertThat( assertGetFunctionRS(rs), is(1) );
-
-    statement.execute("set search_path=nofunctions");
-
-    rs = dbmd.getFunctions("", "","addfunction");
-    assertFalse(rs.next());
-
-    statement.execute("reset search_path");
-    statement.close();
+    try (ResultSet rs = dbmd.getFunctions("", "hasfunctions","")) {
+      List<CatalogObject> list = assertFunctionRSAndReturnList(rs);
+      assertEquals("There should be one function in the hasfunctions schema", list.size(), 1);
+      assertListContains("getFunctions('', 'hasfunctions', '') must contain addfunction", list, "hasfunctions", "addfunction");
+    }
 
-    rs = dbmd.getFunctions("", "nofunctions",null);
-    assertFalse(rs.next());
+    try (ResultSet rs = dbmd.getFunctions("", "hasfunctions", "addfunction")) {
+      List<CatalogObject> list = assertFunctionRSAndReturnList(rs);
+      assertEquals("There should be one function in the hasfunctions schema with name addfunction", list.size(), 1);
+      assertListContains("getFunctions('', 'hasfunctions', 'addfunction') must contain addfunction", list, "hasfunctions", "addfunction");
+    }
 
+    try (ResultSet rs = dbmd.getFunctions("", "nofunctions","")) {
+      boolean hasFunctions = rs.next();
+      assertFalse("There should be no functions in the nofunctions schema", hasFunctions);
+    }
   }
 
   @Test
   public void testGetFunctionsInSchemaForProcedures() throws SQLException {
     // Due to the introduction of actual stored procedures in PostgreSQL 11, getFunctions should not return procedures for PostgreSQL versions 11+
-    if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11)) {
-
-      DatabaseMetaData dbmd = conn.getMetaData();
-      Statement statement = conn.createStatement();
-
-      // Search for functions in schema "hasprocedures"
-      ResultSet rs = dbmd.getFunctions("", "hasprocedures", null);
-      Boolean recordFound = rs.next();
-      assertEquals("PostgreSQL11+ should not return procedures from getFunctions", recordFound, false);
-
-      // Search for functions in schema "noprocedures" (which should never expect records)
-      rs = dbmd.getFunctions("", "noprocedures", null);
-      recordFound = rs.next();
-      assertFalse(recordFound);
-
-      // Search for functions by procedure name "addprocedure" within schema "hasprocedures"
-      statement.execute("set search_path=hasprocedures");
-      rs = dbmd.getFunctions("", "", "addprocedure");
-      recordFound = rs.next();
-      assertEquals("PostgreSQL11+ should not return procedures from getFunctions", recordFound, false);
-
-      // Search for functions by procedure name "addprocedure" within schema "noprocedures"  (which should never expect records)
-      statement.execute("set search_path=noprocedures");
-      rs = dbmd.getProcedures("", "", "addprocedure");
-      recordFound = rs.next();
-      assertFalse(recordFound);
+    // On older installation we do not create the procedures so the below schemas should all be empty
+    DatabaseMetaData dbmd = conn.getMetaData();
 
-      statement.close();
+    // Search for functions in schema "hasprocedures"
+    try (ResultSet rs = dbmd.getFunctions("", "hasprocedures", null)) {
+      assertFalse("The hasprocedures schema not return procedures from getFunctions", rs.next());
+    }
+    // Search for functions in schema "noprocedures" (which should never expect records)
+    try (ResultSet rs = dbmd.getFunctions("", "noprocedures", null)) {
+      assertFalse("The noprocedures schema should not have functions", rs.next());
+    }
+    // Search for functions by procedure name "addprocedure"
+    try (ResultSet rs = dbmd.getFunctions("", "hasprocedures", "addprocedure")) {
+      assertFalse("Should not return procedures from getFunctions by schema + name", rs.next());
     }
   }
 
   @Test
   public void testGetProceduresInSchemaForFunctions() throws SQLException {
     // Due to the introduction of actual stored procedures in PostgreSQL 11, getProcedures should not return functions for PostgreSQL versions 11+
-
     DatabaseMetaData dbmd = conn.getMetaData();
-    Statement statement = conn.createStatement();
 
     // Search for procedures in schema "hasfunctions" (which should expect a record only for PostgreSQL < 11)
-    ResultSet rs = dbmd.getProcedures("", "hasfunctions",null);
-    Boolean recordFound = rs.next();
-    if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11)) {
-      assertEquals("PostgreSQL11+ should not return functions from getProcedures", recordFound, false);
-    } else {
-      assertEquals("PostgreSQL prior to 11 should return functions from getProcedures", recordFound, true);
+    try (ResultSet rs = dbmd.getProcedures("", "hasfunctions",null)) {
+      if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11)) {
+        assertFalse("PostgreSQL11+ should not return functions from getProcedures", rs.next());
+      } else {
+        // PostgreSQL prior to 11 should return functions from getProcedures
+        assertProcedureRS(rs);
+      }
     }
 
     // Search for procedures in schema "nofunctions" (which should never expect records)
-    rs = dbmd.getProcedures("", "nofunctions",null);
-    recordFound = rs.next();
-    assertFalse(recordFound);
+    try (ResultSet rs = dbmd.getProcedures("", "nofunctions", null)) {
+      assertFalse("getProcedures(...) should not return procedures for schema nofunctions", rs.next());
+    }
 
     // Search for procedures by function name "addfunction" within schema "hasfunctions" (which should expect a record for PostgreSQL < 11)
-    statement.execute("set search_path=hasfunctions");
-    rs = dbmd.getProcedures("", "","addfunction");
-    recordFound = rs.next();
-    if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11)) {
-      assertEquals("PostgreSQL11+ should not return functions from getProcedures", recordFound, false);
-    } else {
-      assertEquals("PostgreSQL prior to 11 should return functions from getProcedures", recordFound, true);
+    try (ResultSet rs = dbmd.getProcedures("", "hasfunctions", "addfunction")) {
+      if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11)) {
+        assertFalse("PostgreSQL11+ should not return functions from getProcedures", rs.next());
+      } else {
+        // PostgreSQL prior to 11 should return functions from getProcedures
+        assertProcedureRS(rs);
+      }
     }
 
     // Search for procedures by function name "addfunction" within schema "nofunctions"  (which should never expect records)
-    statement.execute("set search_path=nofunctions");
-    rs = dbmd.getProcedures("", "","addfunction");
-    recordFound = rs.next();
-    assertFalse(recordFound);
-
-    statement.close();
+    try (ResultSet rs = dbmd.getProcedures("", "nofunctions", "addfunction")) {
+      assertFalse("getProcedures(...) should not return procedures for schema nofunctions + addfunction", rs.next());
+    }
   }
 
   @Test
   public void testGetProceduresInSchemaForProcedures() throws SQLException {
     // Only run this test for PostgreSQL version 11+; assertions for versions prior would be vacuously true as we don't create a procedure in the setup for older versions
-    if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11)) {
-      DatabaseMetaData dbmd = conn.getMetaData();
-      Statement statement = conn.createStatement();
+    Assume.assumeTrue(TestUtil.haveMinimumServerVersion(conn, ServerVersion.v11));
 
-      ResultSet rs = dbmd.getProcedures("", "hasprocedures", null);
-      assertTrue(rs.next());
+    DatabaseMetaData dbmd = conn.getMetaData();
 
-      rs = dbmd.getProcedures("", "nofunctions", null);
-      assertFalse(rs.next());
+    try (ResultSet rs = dbmd.getProcedures("", "hasprocedures", null)) {
+      int count = assertProcedureRS(rs);
+      assertTrue("getProcedures() should be non-empty for the hasprocedures schema", count == 1);
+    }
 
-      statement.execute("set search_path=hasprocedures");
-      rs = dbmd.getProcedures("", "", "addprocedure");
-      assertTrue(rs.next());
+    try (ResultSet rs = dbmd.getProcedures("", "noprocedures", null)) {
+      assertFalse("getProcedures() should be empty for the hasprocedures schema", rs.next());
+    }
 
-      statement.execute("set search_path=noprocedures");
-      rs = dbmd.getProcedures("", "", "addprocedure");
-      assertFalse(rs.next());
+    try (ResultSet rs = dbmd.getProcedures("", "hasfunctions", null)) {
+      assertFalse("getProcedures() should be empty for the nofunctions schema", rs.next());
+    }
 
-      statement.close();
+    try (ResultSet rs = dbmd.getProcedures("", "nofunctions", null)) {
+      assertFalse("getProcedures() should be empty for the nofunctions schema", rs.next());
     }
   }
 
@@ -235,46 +215,108 @@ public class DatabaseMetaDataTest {
   public void testGetFunctionsWithBlankPatterns() throws SQLException {
     int minFuncCount = 1000;
     DatabaseMetaData dbmd = conn.getMetaData();
-    ResultSet rs = dbmd.getFunctions("", "", "");
-    int count = assertGetFunctionRS(rs);
-    assertThat(count > minFuncCount, is(true));
+
+    final int totalCount;
+    try (ResultSet rs = dbmd.getFunctions("", "", "")) {
+      List<CatalogObject> list = assertFunctionRSAndReturnList(rs);
+      totalCount = list.size(); // Rest of this test will validate against this value
+      assertThat(totalCount > minFuncCount, is(true));
+      assertListContains("getFunctions('', '', '') must contain addfunction", list, "hasfunctions", "addfunction");
+    }
 
     // Should be same as blank pattern
-    ResultSet rs2 = dbmd.getFunctions(null, null, null);
-    int count2 = assertGetFunctionRS(rs2);
-    assertThat(count2 > minFuncCount, is(true));
-    assertThat(count2, is(count));
+    try (ResultSet rs = dbmd.getFunctions(null, null, null)) {
+      int count = assertGetFunctionRS(rs);
+      assertThat(count, is(totalCount));
+    }
 
     // Catalog parameter has no affect on our getFunctions filtering
-    ResultSet rs3 = dbmd.getFunctions("ANYTHING_WILL_WORK", null, null);
-    int count3 = assertGetFunctionRS(rs3);
-    assertThat(count3 > minFuncCount, is(true));
-    assertThat(count3, is(count));
+    try (ResultSet rs = dbmd.getFunctions("ANYTHING_WILL_WORK", null, null)) {
+      int count = assertGetFunctionRS(rs);
+      assertThat(count, is(totalCount));
+    }
 
     // Filter by schema
-    ResultSet rs4 = dbmd.getFunctions("", "pg_catalog", null);
-    int count4 = assertGetFunctionRS(rs4);
-    assertThat(count4 > minFuncCount, is(true));
+    try (ResultSet rs = dbmd.getFunctions("", "pg_catalog", null)) {
+      int count = assertGetFunctionRS(rs);
+      assertThat(count > minFuncCount, is(true));
+    }
 
     // Filter by schema and function name
-    ResultSet rs5 = dbmd.getFunctions("", "pg_catalog", "abs");
-    int count5 = assertGetFunctionRS(rs5);
-    assertThat(count5 >= 1, is(true));
+    try (ResultSet rs = dbmd.getFunctions("", "pg_catalog", "abs")) {
+      int count = assertGetFunctionRS(rs);
+      assertThat(count >= 1, is(true));
+    }
 
     // Filter by function name only
-    rs5 = dbmd.getFunctions("", "", "abs");
-    count5 = assertGetFunctionRS(rs5);
-    assertThat(count5 >= 1, is(true));
-
-    rs.close();
-    rs2.close();
-    rs3.close();
-    rs4.close();
-    rs5.close();
+    try (ResultSet rs = dbmd.getFunctions("", "", "abs")) {
+      int count = assertGetFunctionRS(rs);
+      assertThat(count >= 1, is(true));
+    }
+  }
+
+  private static class CatalogObject implements Comparable<CatalogObject> {
+    private final String catalog;
+    private final String schema;
+    private final String name;
+    private final String specificName;
+
+    private CatalogObject(String catalog, String schema, String name, String specificName) {
+      this.catalog = catalog;
+      this.schema = schema;
+      this.name = name;
+      this.specificName = specificName;
+    }
+
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
+      result = prime * result + ((name == null) ? 0 : name.hashCode());
+      result = prime * result + ((schema == null) ? 0 : schema.hashCode());
+      result = prime * result + ((specificName == null) ? 0 : specificName.hashCode());
+      return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (obj == null || getClass() != obj.getClass()) {
+        return false;
+      } else if (obj == this) {
+        return true;
+      }
+      return compareTo((CatalogObject)obj) == 0;
+    }
+
+    @Override
+    public int compareTo(CatalogObject other) {
+      int comp = catalog.compareTo(other.catalog);
+      if (comp != 0) {
+        return comp;
+      }
+      comp = schema.compareTo(other.schema);
+      if (comp != 0) {
+        return comp;
+      }
+      comp = name.compareTo(other.name);
+      if (comp != 0) {
+        return comp;
+      }
+      comp = specificName.compareTo(other.specificName);
+      if (comp != 0) {
+        return comp;
+      }
+      return 0;
+    }
   }
 
   /** Assert some basic result from ResultSet of a GetFunctions method. Return the total row count. */
   private int assertGetFunctionRS(ResultSet rs) throws SQLException {
+    return assertFunctionRSAndReturnList(rs).size();
+  }
+
+  private List<CatalogObject> assertFunctionRSAndReturnList(ResultSet rs) throws SQLException {
     // There should be at least one row
     assertThat(rs.next(), is(true));
     assertThat(rs.getString("FUNCTION_CAT"), is(System.getProperty("database")));
@@ -294,22 +336,68 @@ public class DatabaseMetaDataTest {
 
     // Get all result and assert they are ordered per javadoc spec:
     //   FUNCTION_CAT, FUNCTION_SCHEM, FUNCTION_NAME and SPECIFIC_NAME
-    List<String> result = new ArrayList<String>();
+    List<CatalogObject> result = new ArrayList<>();
     do {
-      result.add(rs.getString("FUNCTION_CAT")
-              + " "
-              + rs.getString("FUNCTION_SCHEM")
-              + " "
-              + rs.getString("FUNCTION_NAME")
-              + " "
-              + rs.getString("SPECIFIC_NAME"));
+      CatalogObject obj = new CatalogObject(
+          rs.getString("FUNCTION_CAT"),
+          rs.getString("FUNCTION_SCHEM"),
+          rs.getString("FUNCTION_NAME"),
+          rs.getString("SPECIFIC_NAME"));
+      result.add(obj);
     } while (rs.next());
 
-    List<String> orderedResult = new ArrayList<String>(result);
+    List<CatalogObject> orderedResult = new ArrayList<>(result);
     Collections.sort(orderedResult);
     assertThat(result, is(orderedResult));
 
-    return result.size();
+    return result;
+  }
+
+  private int assertProcedureRS(ResultSet rs) throws SQLException {
+    return assertProcedureRSAndReturnList(rs).size();
+  }
+
+  private List<CatalogObject> assertProcedureRSAndReturnList(ResultSet rs) throws SQLException {
+    // There should be at least one row
+    assertThat(rs.next(), is(true));
+    assertThat(rs.getString("PROCEDURE_CAT"), nullValue());
+    assertThat(rs.getString("PROCEDURE_SCHEM"), notNullValue());
+    assertThat(rs.getString("PROCEDURE_NAME"), notNullValue());
+    assertThat(rs.getShort("PROCEDURE_TYPE") >= 0, is(true));
+    assertThat(rs.getString("SPECIFIC_NAME"), notNullValue());
+
+    // Ensure there is enough column and column value retrieve by index should be same as column name (ordered)
+    assertThat(rs.getMetaData().getColumnCount(), is(9));
+    assertThat(rs.getString(1), is(rs.getString("PROCEDURE_CAT")));
+    assertThat(rs.getString(2), is(rs.getString("PROCEDURE_SCHEM")));
+    assertThat(rs.getString(3), is(rs.getString("PROCEDURE_NAME")));
+    // Per JDBC spec, indexes 4, 5, and 6 are reserved for future use
+    assertThat(rs.getString(7), is(rs.getString("REMARKS")));
+    assertThat(rs.getShort(8), is(rs.getShort("PROCEDURE_TYPE")));
+    assertThat(rs.getString(9), is(rs.getString("SPECIFIC_NAME")));
+
+    // Get all result and assert they are ordered per javadoc spec:
+    //   FUNCTION_CAT, FUNCTION_SCHEM, FUNCTION_NAME and SPECIFIC_NAME
+    List<CatalogObject> result = new ArrayList<>();
+    do {
+      CatalogObject obj = new CatalogObject(
+          rs.getString("PROCEDURE_CAT"),
+          rs.getString("PROCEDURE_SCHEM"),
+          rs.getString("PROCEDURE_NAME"),
+          rs.getString("SPECIFIC_NAME"));
+      result.add(obj);
+    } while (rs.next());
+
+    List<CatalogObject> orderedResult = new ArrayList<>(result);
+    Collections.sort(orderedResult);
+    assertThat(result, is(orderedResult));
+
+    return result;
+  }
+
+  private void assertListContains(String message, List<CatalogObject> list, String schema, String name) throws SQLException {
+    boolean found = list.stream().anyMatch(item -> item.schema.equals(schema) && item.name.equals(name));
+    assertTrue(message + "; schema=" + schema + " name=" + name, found);
   }
 
   @Test



View it on GitLab: https://salsa.debian.org/java-team/libpostgresql-jdbc-java/-/compare/c2fa08efebc5c9e20ba379f1209a059cbefc8e1d...07032436a6f0d744784c53540c0cc472d6f4d03c

-- 
View it on GitLab: https://salsa.debian.org/java-team/libpostgresql-jdbc-java/-/compare/c2fa08efebc5c9e20ba379f1209a059cbefc8e1d...07032436a6f0d744784c53540c0cc472d6f4d03c
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20210630/6902d5be/attachment.htm>


More information about the pkg-java-commits mailing list