Re: Allow the jdbc driver to retrieve NAMEDATALEN - Mailing list pgsql-patches
From | Barry Lind |
---|---|
Subject | Re: Allow the jdbc driver to retrieve NAMEDATALEN |
Date | |
Msg-id | 3D7ED9BC.1010300@xythos.com Whole thread Raw |
In response to | Allow the jdbc driver to retrieve NAMEDATALEN (Kris Jurka <jurka@ejurka.com>) |
List | pgsql-patches |
Patch applied. --Barry Kris Jurka wrote: > > 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 Jurka > > > ------------------------------------------------------------------------ > > Index: 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. > } > } > > > > > ------------------------------------------------------------------------ > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org
pgsql-patches by date: