Allow the jdbc driver to retrieve NAMEDATALEN - Mailing list pgsql-patches

From Kris Jurka
Subject Allow the jdbc driver to retrieve NAMEDATALEN
Date
Msg-id 3D7AB1E2.29DC5C8E@ejurka.com
Whole thread Raw
List pgsql-patches

Make the DatabaseMetaData class query the backend to determine the
maximum name length instead of guessing.

Also the maximum name length is NAMEDATALEN - 1.

Kris JurkaIndex: src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java,v
retrieving revision 1.5
diff -c -r1.5 AbstractJdbc1DatabaseMetaData.java
*** src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java    2002/09/08 00:15:28    1.5
--- src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java    2002/09/08 02:11:04
***************
*** 27,45 ****
      protected static final int iInt2Oid = 21; // OID for int2
      protected static final int iInt4Oid = 23; // OID for int4
      protected static final int VARHDRSZ = 4;    // length for int4
!     protected static int NAME_SIZE = 64;    // length for name datatype

      public AbstractJdbc1DatabaseMetaData(AbstractJdbc1Connection conn)
      {
          this.connection = conn;
          try {
              if (connection.haveMinimumServerVersion("7.3")) {
!                 NAME_SIZE = 64;
              } else {
!                 NAME_SIZE = 32;
              }
          } catch (SQLException l_se) {
!             //leave value at default
          }
      }

--- 27,54 ----
      protected static final int iInt2Oid = 21; // OID for int2
      protected static final int iInt4Oid = 23; // OID for int4
      protected static final int VARHDRSZ = 4;    // length for int4
!     protected static int NAME_SIZE = 63;    // length for name datatype

      public AbstractJdbc1DatabaseMetaData(AbstractJdbc1Connection conn)
      {
          this.connection = conn;
+         String sql;
          try {
              if (connection.haveMinimumServerVersion("7.3")) {
!                 sql = "SELECT t.typlen FROM pg_catalog.pg_type t, pg_catalog.pg_namespace n WHERE
t.typnamespace=n.oidAND t.typname='name' AND n.nspname='pg_catalog'"; 
!                 NAME_SIZE = 63;
              } else {
!                 sql = "SELECT typlen FROM pg_type WHERE typname='name'";
!                 NAME_SIZE = 31;
              }
+             ResultSet rs = connection.createStatement().executeQuery(sql);
+             if (rs.next()) {
+                 NAME_SIZE = rs.getInt("typlen") - 1;
+             }
+             rs.close();
          } catch (SQLException l_se) {
!             // depending on the error the NAME_SIZE value will
!             // be the original or the value set before the query.
          }
      }



pgsql-patches by date:

Previous
From: "Serguei Mokhov"
Date:
Subject: Russian NLS Updates (pg_controldata, psql, pg_resetxlog, libpq)
Next
From: "Serguei Mokhov"
Date:
Subject: [g]make distclean does not remove gettext-files