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

Re: getProcedureColumns

From: "thomas(dot)risberg" <thomas(dot)risberg(at)tridb(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: getProcedureColumns
Date: 2007-07-02 17:29:55
Message-ID: 11398134.post@talk.nabble.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Hi,

Did this patch ever make it into the codebase?  I'm interested in getting
the actual names declared when the function was declared rather than the $x
placeholders.  Currently testing with postgresql-8.2-505.jdbc3.jar and this
change doesn't seem to be in there.

Thanks,
Thomas Risberg



Kris Jurka wrote:
> 
> 
> 
> On Wed, 14 Feb 2007, Jeffrey Cox wrote:
> 
>> I know it's a pain, but I will test it... I just need to get the all the 
>> servers up and running. It might take me some time to get them up and
>> going, 
>> but shouldn't be to troubling.
> 
> Here's a patch that I based off of yours.  For 8.1 code we need to look at 
> proallargtypes instead of just proargtypes to get the correct output 
> types.  I haven't really tested it, but it looks correct.  Any progress on 
> setting up test cases for different server versions?
> 
> Kris Jurka
> ? .build.local.properties.swp
> ? build.local.properties
> ? getproccol.patch
> Index: org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
> ===================================================================
> RCS file:
> /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v
> retrieving revision 1.33
> diff -c -r1.33 AbstractJdbc2DatabaseMetaData.java
> *** org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java	1 Dec 2006
> 08:53:45 -0000	1.33
> --- org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java	28 Feb 2007
> 07:39:43 -0000
> ***************
> *** 1724,1731 ****
>           String sql;
>           if (connection.haveMinimumServerVersion("7.3"))
>           {
> !             sql = "SELECT
> n.nspname,p.proname,p.prorettype,p.proargtypes, 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))
>               {
> --- 1724,1739 ----
>           String sql;
>           if (connection.haveMinimumServerVersion("7.3"))
>           {
> !             sql = "SELECT
> n.nspname,p.proname,p.prorettype,p.proargtypes, t.typtype,t.typrelid ";
> ! 
> !             if (connection.haveMinimumServerVersion("8.1"))
> !                 sql += ", p.proargnames, p.proargmodes, p.proallargtypes 
> ";
> !             else if (connection.haveMinimumServerVersion("8.0"))
> !                 sql += ", p.proargnames, NULL AS proargmodes, NULL AS
> proallargtypes ";
> !             else
> !                 sql += ", NULL AS proargnames, NULL AS proargmodes, NULL
> AS proallargtypes ";
> ! 
> !             sql += " 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))
>               {
> ***************
> *** 1739,1745 ****
>           }
>           else
>           {
> !             sql = "SELECT NULL AS
> nspname,p.proname,p.prorettype,p.proargtypes, t.typtype,t.typrelid " +
>                     " FROM pg_proc p,pg_type t " +
>                     " WHERE p.prorettype=t.oid ";
>               if (procedureNamePattern != null)
> --- 1747,1753 ----
>           }
>           else
>           {
> !             sql = "SELECT NULL AS
> nspname,p.proname,p.prorettype,p.proargtypes,t.typtype,t.typrelid, NULL AS
> proargnames, NULL AS proargmodes, NULL AS proallargtypes " +
>                     " FROM pg_proc p,pg_type t " +
>                     " WHERE p.prorettype=t.oid ";
>               if (procedureNamePattern != null)
> ***************
> *** 1757,1768 ****
>               int returnType = rs.getInt("prorettype");
>               String returnTypeType = rs.getString("typtype");
>               int returnTypeRelid = rs.getInt("typrelid");
>               String strArgTypes = rs.getString("proargtypes");
>               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.
> --- 1765,1796 ----
>               int returnType = rs.getInt("prorettype");
>               String returnTypeType = rs.getString("typtype");
>               int returnTypeRelid = rs.getInt("typrelid");
> + 
>               String strArgTypes = rs.getString("proargtypes");
>               StringTokenizer st = new StringTokenizer(strArgTypes);
>               Vector argTypes = new Vector();
>               while (st.hasMoreTokens())
>               {
> !                 argTypes.addElement(new Long(st.nextToken()));
> !             }
> ! 
> !             String argNames[] = null;
> !             Array argNamesArray = rs.getArray("proargnames");
> !             if (argNamesArray != null)
> !                 argNames = (String[])argNamesArray.getArray();
> ! 
> !             String argModes[] = null;
> !             Array argModesArray = rs.getArray("proargmodes");
> !             if (argModesArray != null)
> !                 argModes = (String[])argModesArray.getArray();
> ! 
> !             int numArgs = argTypes.size();
> ! 
> !             long allArgTypes[] = null;
> !             Array allArgTypesArray = rs.getArray("proallargtypes");
> !             if (allArgTypesArray != null) {
> !                 allArgTypes = (long[])allArgTypesArray.getArray();
> !                 numArgs = allArgTypes.length;
>               }
>   
>               // decide if we are returning a single column result.
> ***************
> *** 1786,1807 ****
>               }
>   
>               // Add a row for each argument.
> !             for (int i = 0; i < argTypes.size(); i++)
>               {
> -                 int argOid =
> ((Integer)argTypes.elementAt(i)).intValue();
>                   byte[][] tuple = new byte[13][];
>                   tuple[0] = null;
>                   tuple[1] = schema;
>                   tuple[2] = procedureName;
> !                 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));
>                   tuple[7] = null;
>                   tuple[8] = null;
>                   tuple[9] = null;
>                   tuple[10] = null;
> !                 tuple[11] =
> connection.encodeString(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown));
>                   tuple[12] = null;
>                   v.addElement(tuple);
>               }
> --- 1814,1852 ----
>               }
>   
>               // Add a row for each argument.
> !             for (int i = 0; i < numArgs; i++)
>               {
>                   byte[][] tuple = new byte[13][];
>                   tuple[0] = null;
>                   tuple[1] = schema;
>                   tuple[2] = procedureName;
> ! 
> !                 if (argNames != null)
> !                     tuple[3] = connection.encodeString(argNames[i]);
> !                 else
> !                     tuple[3] = connection.encodeString("$" + (i + 1));
> ! 
> !                 int columnMode = DatabaseMetaData.procedureColumnIn;
> !                 if (argModes != null && argModes[i].equals("o"))
> !                     columnMode = DatabaseMetaData.procedureColumnOut;
> !                 else if (argModes != null && argModes[i].equals("b"))
> !                     columnMode = DatabaseMetaData.procedureColumnInOut;
> ! 
> !                 tuple[4] =
> connection.encodeString(Integer.toString(columnMode));
> ! 
> !                 int argOid;
> !                 if (allArgTypes != null)
> !                     argOid = (int)allArgTypes[i];
> !                 else
> !                     argOid = ((Long)argTypes.elementAt(i)).intValue();
> ! 
>                   tuple[5] =
> connection.encodeString(Integer.toString(connection.getSQLType(argOid)));
>                   tuple[6] =
> connection.encodeString(connection.getPGType(argOid));
>                   tuple[7] = null;
>                   tuple[8] = null;
>                   tuple[9] = null;
>                   tuple[10] = null;
> !                 tuple[11] =
> connection.encodeString(Integer.toString(DatabaseMetaData.procedureNullableUnknown));
>                   tuple[12] = null;
>                   v.addElement(tuple);
>               }
> ***************
> *** 1830,1835 ****
> --- 1875,1881 ----
>                       tuple[12] = null;
>                       v.addElement(tuple);
>                   }
> +                 columnrs.close();
>               }
>           }
>           rs.close();
> Index: org/postgresql/jdbc2/TypeInfoCache.java
> ===================================================================
> RCS file:
> /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/TypeInfoCache.java,v
> retrieving revision 1.7
> diff -c -r1.7 TypeInfoCache.java
> *** org/postgresql/jdbc2/TypeInfoCache.java	19 Feb 2007 05:57:53 -0000	1.7
> --- org/postgresql/jdbc2/TypeInfoCache.java	28 Feb 2007 07:39:43 -0000
> ***************
> *** 57,62 ****
> --- 57,63 ----
>           {"numeric", new Integer(Oid.NUMERIC), new
> Integer(Types.NUMERIC), "java.math.BigDecimal"},
>           {"float4", new Integer(Oid.FLOAT4), new Integer(Types.REAL),
> "java.lang.Float"},
>           {"float8", new Integer(Oid.FLOAT8), new Integer(Types.DOUBLE),
> "java.lang.Double"},
> + 	{"char", new Integer(Oid.CHAR), new Integer(Types.CHAR),
> "java.lang.String"},
>           {"bpchar", new Integer(Oid.BPCHAR), new Integer(Types.CHAR),
> "java.lang.String"},
>           {"varchar", new Integer(Oid.VARCHAR), new
> Integer(Types.VARCHAR), "java.lang.String"},
>           {"text", new Integer(Oid.TEXT), new Integer(Types.VARCHAR),
> "java.lang.String"},
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 
> 

-- 
View this message in context: http://www.nabble.com/getProcedureColumns-tf3147414.html#a11398134
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


In response to

Responses

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2007-07-02 17:36:55
Subject: Re: getProcedureColumns
Previous:From: Loredana CurugiuDate: 2007-07-02 16:49:54
Subject: Re: Replace usage of a table in query with its array values

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