This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 8a78e93  Recognize more array component types in PostgreSQL database.
8a78e93 is described below

commit 8a78e93d78b7fa3fe5fa3311ae36320262f5b7c1
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Mar 16 11:11:16 2022 +0100

    Recognize more array component types in PostgreSQL database.
---
 .../org/apache/sis/internal/sql/postgis/Postgres.java   | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/postgis/Postgres.java
 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/postgis/Postgres.java
index 3c4ec10..6faf3e3 100644
--- 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/postgis/Postgres.java
+++ 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/postgis/Postgres.java
@@ -17,7 +17,9 @@
 package org.apache.sis.internal.sql.postgis;
 
 import java.util.Map;
+import java.util.Locale;
 import java.sql.Types;
+import java.sql.JDBCType;
 import java.sql.Connection;
 import java.sql.Statement;
 import java.sql.ResultSet;
@@ -53,6 +55,10 @@ import org.apache.sis.util.Version;
 public final class Postgres<G> extends Database<G> {
     /**
      * Version of PostGIS extension, or {@code null} if PostGIS has not been 
found.
+     * Not to be confused with the version of PostgreSQL server, which is 
given by
+     * another class provided in the PostgreSQL JDBC driver.
+     *
+     * @see org.postgresql.core.ServerVersion
      */
     private final Version postgisVersion;
 
@@ -131,9 +137,14 @@ public final class Postgres<G> extends Database<G> {
      */
     @Override
     protected int getArrayComponentType(final Column columnDefinition) {
-        switch (columnDefinition.typeName) {
-            // More types to be added later.
-            case "_text": return Types.VARCHAR;
+        String typeName = columnDefinition.typeName;
+        if (typeName.equalsIgnoreCase("_text")) {       // Common case.
+            return Types.VARCHAR;
+        }
+        if (typeName.length() >= 2 && typeName.charAt(0) == '_') try {
+            return 
JDBCType.valueOf(typeName.substring(1).toUpperCase(Locale.US)).getVendorTypeNumber();
+        } catch (IllegalArgumentException e) {
+            // Unknown type. Ignore and fallback on `Types.OTHER`.
         }
         return super.getArrayComponentType(columnDefinition);
     }

Reply via email to