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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

getProcedureColumns



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
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));



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group