Skip site navigation (1) Skip section navigation (2)

Re: Allow the jdbc driver to retrieve NAMEDATALEN

From: Barry Lind <barry(at)xythos(dot)com>
To: Kris Jurka <jurka(at)ejurka(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Allow the jdbc driver to retrieve NAMEDATALEN
Date: 2002-09-11 05:50:52
Message-ID: 3D7ED9BC.1010300@xythos.com (view raw or flat)
Thread:
Lists: 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.oid AND 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


In response to

pgsql-patches by date

Next:From: Kris JurkaDate: 2002-09-11 07:19:25
Subject: Re: JDBC Driver Database Meta Data - FK_NAME
Previous:From: Barry LindDate: 2002-09-11 05:50:34
Subject: Re: JDBC Driver Test Suite Drop Table w/ Cascade

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group