From: Jeffrey Cox <namredips@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: getProcedureColumns
Date: Wed, 31 Jan 2007 03:29:51 -0500
Message-ID: <1C85230A-C17D-4601-B84E-6F43176C5D6D@gmail.com> (raw)
Hi,
I been working with metadata on stored procedures and discovered
that I can't get parameter names via getProcedureColumns. So i
checked out the source and took a look at the method. Seems that for
column names, a $ is appended to the arg type count. I guess I don't
know if there is a reason that the actual parameter names are not
used, or its just low on the TODO list. I went ahead and updated the
method return column names as stored in procargnames of
pg_catalog.pg_proc. I have attached a patch.
I honestly don't know if this is the correct mechanism to handle this
(I poped into #postgres and was told to attach a patch to an email to
this list), so just point me in the right direction if need be
(either on how to submit the patch, or why making this change is
stupid).
Jeff
Attachments:postgres-jdbc-patch.rtf (text/rtf, 2.8K) download
Index: org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v
retrieving revision 1.33
diff -u -r1.33 AbstractJdbc2DatabaseMetaData.java
--- org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 1 Dec 2006 08:53:45 -0000 1.33
+++ org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 31 Jan 2007 08:15:35 -0000
@@ -1724,9 +1724,15 @@
String sql;
if (connection.haveMinimumServerVersion("7.3"))
{
- sql = "SELECT n.nspname,p.proname,p.prorettype,p.proargtypes, t.typtype,t.typrelid " +
+ sql = "SELECT n.nspname,p.proname,p.prorettype,p.proargtypes, ";
+
+ if(connection.haveMinimumCompatibleVersion("8.0"))
+ sql += "p.proargnames,";
+
+ sql += "t.typtype,t.typrelid " +
" FROM pg_catalog.pg_proc p,pg_catalog.pg_namespace n, pg_catalog.pg_type t " +
" WHERE p.pronamespace=n.oid AND p.prorettype=t.oid ";
+
if (schemaPattern != null && !"".equals(schemaPattern))
{
sql += " AND n.nspname LIKE '" + escapeQuotes(schemaPattern) + "' ";
@@ -1758,13 +1764,18 @@
String returnTypeType = rs.getString("typtype");
int returnTypeRelid = rs.getInt("typrelid");
String strArgTypes = rs.getString("proargtypes");
+ String strArgNames[] = null;
+ Array argNamesArray = rs.getArray("proargnames");
+ if(argNamesArray != null)
+ strArgNames = (String[])argNamesArray.getArray();
StringTokenizer st = new StringTokenizer(strArgTypes);
Vector argTypes = new Vector();
while (st.hasMoreTokens())
{
argTypes.addElement(new Integer(st.nextToken()));
}
-
+
+
// decide if we are returning a single column result.
if (!returnTypeType.equals("c"))
{
@@ -1793,7 +1804,14 @@
tuple[0] = null;
tuple[1] = schema;
tuple[2] = procedureName;
- tuple[3] = connection.encodeString("$" + (i + 1));
+ if(strArgNames != null)
+ {
+ tuple[3] = connection.encodeString(strArgNames[i]);
+ }
+ else
+ {
+ tuple[3] = connection.encodeString("$" + (i + 1));
+ }
tuple[4] = connection.encodeString(Integer.toString(java.sql.DatabaseMetaData.procedureColumnIn));
tuple[5] = connection.encodeString(Integer.toString(connection.getSQLType(argOid)));
tuple[6] = connection.encodeString(connection.getPGType(argOid));
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: namredips@gmail.com
Subject: Re: getProcedureColumns
In-Reply-To: <1C85230A-C17D-4601-B84E-6F43176C5D6D@gmail.com>
References: <1C85230A-C17D-4601-B84E-6F43176C5D6D@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox