pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
patch for getUDT
5+ messages / 2 participants
[nested] [flat]

* patch for getUDT
@ 2004-05-13 14:58  Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Dave Cramer @ 2004-05-13 14:58 UTC (permalink / raw)
  To: pgsql-jdbc

Here's a patch for getUDT, I'll apply it if nobody complains..

-- 
Dave Cramer
519 939 0336
ICQ # 14675561

Attachments:

UDT.diff (text/x-patch, 6.9K) download Index: test/jdbc2/DatabaseMetaDataTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v retrieving revision 1.22 diff -c -b -B -r1.22 DatabaseMetaDataTest.java *** test/jdbc2/DatabaseMetaDataTest.java 12 Dec 2003 18:30:27 -0000 1.22 --- test/jdbc2/DatabaseMetaDataTest.java 13 May 2004 14:23:31 -0000 *************** *** 524,527 **** --- 524,620 ---- } } + public void testGetUDTQualified() + { + Statement stmt = null; + try + { + stmt = con.createStatement(); + stmt.execute("create schema jdbc"); + stmt.execute("create type jdbc.testint8 as (i int8)"); + DatabaseMetaData dbmd = con.getMetaData(); + ResultSet rs = dbmd.getUDTs(null, null ,"jdbc.testint8" , null); + assertTrue(rs.next()); + String cat, schema, typeName, remarks, className; + int dataType; + int baseType; + + cat = rs.getString("type_cat"); + schema = rs.getString("type_schem"); + typeName = rs.getString( "type_name"); + className = rs.getString("class_name"); + dataType = rs.getInt("data_type"); + remarks = rs.getString( "remarks" ); + baseType = rs.getInt("base_type"); + this.assertEquals("type name ", "testint8", typeName); + this.assertEquals("schema name ", "jdbc",schema); + + // now test to see if the fully qualified stuff works as planned + rs = dbmd.getUDTs("catalog", "public" ,"catalog.jdbc.testint8" , null); + assertTrue(rs.next()); + cat = rs.getString("type_cat"); + schema = rs.getString("type_schem"); + typeName = rs.getString( "type_name"); + className = rs.getString("class_name"); + dataType = rs.getInt("data_type"); + remarks = rs.getString( "remarks" ); + baseType = rs.getInt("base_type"); + this.assertEquals("type name ", "testint8", typeName); + this.assertEquals("schema name ", "jdbc",schema); + } + catch( SQLException ex ) + { + fail( ex.getMessage() ); + } + finally + { + try + { + if (stmt != null ) + stmt.close(); + stmt = con.createStatement(); + stmt.execute("drop type jdbc.testint8"); + stmt.execute("drop schema jdbc"); + } + catch( Exception ex ){} + } + + } + public void testGetUDT() + { + try + { + Statement stmt = con.createStatement(); + stmt.execute("create type testint8 as (i int8)"); + DatabaseMetaData dbmd = con.getMetaData(); + ResultSet rs = dbmd.getUDTs(null, null ,"testint8" , null); + assertTrue(rs.next()); + String cat, schema, typeName, remarks, className; + int dataType; + int baseType; + + cat = rs.getString("type_cat"); + schema = rs.getString("type_schem"); + typeName = rs.getString( "type_name"); + className = rs.getString("class_name"); + dataType = rs.getInt("data_type"); + remarks = rs.getString( "remarks" ); + baseType = rs.getInt("base_type"); + this.assertEquals("type name ", "testint8", typeName); + + } + catch( SQLException ex ) + { + fail( ex.getMessage() ); + } + finally + { + try + { + Statement stmt = con.createStatement(); + stmt.execute("drop type testint8"); + } + catch( Exception ex ){} + } + } } Index: jdbc2/AbstractJdbc2DatabaseMetaData.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v retrieving revision 1.7 diff -c -b -B -r1.7 AbstractJdbc2DatabaseMetaData.java *** jdbc2/AbstractJdbc2DatabaseMetaData.java 24 Apr 2004 20:58:16 -0000 1.7 --- jdbc2/AbstractJdbc2DatabaseMetaData.java 13 May 2004 14:23:51 -0000 *************** *** 107,114 **** return true; } ! /* ! * Return user defined types in a schema */ public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, --- 107,120 ---- return true; } ! /** ! * ! * @param catalog String ! * @param schemaPattern String ! * @param typeNamePattern String ! * @param types int[] ! * @throws SQLException ! * @return ResultSet */ public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, *************** *** 116,122 **** int[] types ) throws SQLException { ! throw org.postgresql.Driver.notImplemented(); } --- 122,167 ---- int[] types ) throws SQLException { ! String sql = "select " ! + "null as type_cat, n.nspname as type_schem, t.typname as type_name, " ! + "null as class_name, null as data_type, null as remarks, null as base_type " ! + "from pg_catalog.pg_type t, pg_catalog.pg_namespace n where t.typnamespace = n.oid and t.typname not like 'pg_toast%'"; ! ! String toAdd = ""; ! // spec says that if typeNamePattern is not null then the schema and catalog are ignored ! ! if (typeNamePattern != null) ! { ! // search for qualifier ! int firstQualifier = typeNamePattern.indexOf('.') ; ! int secondQualifier = typeNamePattern.lastIndexOf('.'); ! ! if ( firstQualifier != -1 ) // if one of them is -1 they both will be ! { ! if ( firstQualifier != secondQualifier ) ! { ! // we have a catalog.schema.typename, ignore catalog ! schemaPattern = typeNamePattern.substring(firstQualifier+1, secondQualifier); ! } ! else ! { ! // we just have a schema.typename ! schemaPattern = typeNamePattern.substring(0,firstQualifier); ! } ! // strip out just the typeName ! typeNamePattern = typeNamePattern.substring(secondQualifier+1); ! } ! toAdd += " and t.typname like '" + typeNamePattern + "'"; ! } ! ! // schemaPattern may have been modified above ! if ( schemaPattern != null) ! { ! toAdd += " and n.nspname like '" + schemaPattern +"'"; ! } ! sql += toAdd; ! java.sql.ResultSet rs = connection.createStatement().executeQuery(sql); ! return rs; }
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: patch for getUDT
@ 2004-05-17 22:41  Kris Jurka <books@ejurka.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Kris Jurka @ 2004-05-17 22:41 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc



On Thu, 13 May 2004, Dave Cramer wrote:

> Here's a patch for getUDT, I'll apply it if nobody complains..
> 

It seems to have some problems, most notably the fact that we don't 
support UDTs.  Looking at the javadoc for this function you are returing 
NULL for both class_name and data_type which doesn't look like it's 
allowed as type_cat and type_schem explicitly state their ability to be 
null.  Without class_name and data_type what information are we really 
returning?  If you are really just returning plain type info, how is this 
different/better than getTypeInfo().

If you want to implement it for the sake of implementing it, the docs 
state, "Note: If the driver does not support UDTs, an empty result set is 
returned."  I belive this is the correct thing to do.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: patch for getUDT
@ 2004-05-17 23:24  Dave Cramer <pg@fastcrypt.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Dave Cramer @ 2004-05-17 23:24 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

While we don't support JAVA_OBJECT we do support struct, and distinct.

Dave
On Mon, 2004-05-17 at 18:41, Kris Jurka wrote:
> On Thu, 13 May 2004, Dave Cramer wrote:
> 
> > Here's a patch for getUDT, I'll apply it if nobody complains..
> > 
> 
> It seems to have some problems, most notably the fact that we don't 
> support UDTs.  Looking at the javadoc for this function you are returing 
> NULL for both class_name and data_type which doesn't look like it's 
> allowed as type_cat and type_schem explicitly state their ability to be 
> null.  Without class_name and data_type what information are we really 
> returning?  If you are really just returning plain type info, how is this 
> different/better than getTypeInfo().
> 
> If you want to implement it for the sake of implementing it, the docs 
> state, "Note: If the driver does not support UDTs, an empty result set is 
> returned."  I belive this is the correct thing to do.
> 
> Kris Jurka
> 
> 
> 
> !DSPAM:40a945e1239445479435263!
> 
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: patch for getUDT
@ 2004-05-18 00:20  Kris Jurka <books@ejurka.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Kris Jurka @ 2004-05-18 00:20 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc



On Mon, 17 May 2004, Dave Cramer wrote:

> While we don't support JAVA_OBJECT we do support struct, and distinct.

After doing some more reading I would agree that domains == distinct and
complext types == struct, if that's what you're suggesting.  The patch 
shows no signs of this though, it just blindly selects everything out of 
pg_type.

To be worthy of applying it seems this patch should:

1) Only return domains and complex types, correctly setting data_type and 
base_type for domains.

2) Use pg_description to retrieve a comment for the remarks column.

3) Filter out toast entries by checking pg_namespace.nspname != 'pg_toast' 
instead of using a like expression on type name.

4) Use the escapeQuotes function to ensure that the schema and type 
patterns don't have single quotes in them.

5) Use the types[] parameter to filter out undesired data_type values.

6) Use ORDER BY to return the results in the order the spec says.

7) Use createMetaDataStatement() instead of createStatement() when 
returning the query results.  This makes the produced ResultSet scrollable 
instead of the default forward only behavior.

I would personally like to see a version of this that ran on a 7.2 server 
because the regression tests currently pass against a 7.2 server.  It 
isn't within our stated goals of supporting the past two versions of the 
driver, but I think it's a reasonable thing to do.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: patch for getUDT
@ 2004-05-18 12:18  Dave Cramer <pg@fastcrypt.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Dave Cramer @ 2004-05-18 12:18 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

On Mon, 2004-05-17 at 20:20, Kris Jurka wrote:
> On Mon, 17 May 2004, Dave Cramer wrote:
> 
> > While we don't support JAVA_OBJECT we do support struct, and distinct.
> 
> After doing some more reading I would agree that domains == distinct and
> complext types == struct, if that's what you're suggesting.  The patch 
> shows no signs of this though, it just blindly selects everything out of 
> pg_type.

Yes
> 
> To be worthy of applying it seems this patch should:
> 
> 1) Only return domains and complex types, correctly setting data_type and 
> base_type for domains.
> 
> 2) Use pg_description to retrieve a comment for the remarks column.
> 
> 3) Filter out toast entries by checking pg_namespace.nspname != 'pg_toast' 
> instead of using a like expression on type name.

this must remain, as there will be numerous pg_toast_... entries created
by large columns
> 
> 4) Use the escapeQuotes function to ensure that the schema and type 
> patterns don't have single quotes in them.
> 
> 5) Use the types[] parameter to filter out undesired data_type values.
> 
> 6) Use ORDER BY to return the results in the order the spec says.
> 
> 7) Use createMetaDataStatement() instead of createStatement() when 
> returning the query results.  This makes the produced ResultSet scrollable 
> instead of the default forward only behavior.
> 
> I would personally like to see a version of this that ran on a 7.2 server 
> because the regression tests currently pass against a 7.2 server.  It 
> isn't within our stated goals of supporting the past two versions of the 
> driver, but I think it's a reasonable thing to do.

This probably makes things alot more difficult as schema's don't exist
in 7.2 but...
> 
> Kris Jurka
> 
> 
> 
> !DSPAM:40a956df25291752513779!
> 
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2004-05-18 12:18 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-13 14:58 patch for getUDT Dave Cramer <pg@fastcrypt.com>
2004-05-17 22:41 ` Kris Jurka <books@ejurka.com>
2004-05-17 23:24   ` Dave Cramer <pg@fastcrypt.com>
2004-05-18 00:20     ` Kris Jurka <books@ejurka.com>
2004-05-18 12:18       ` Dave Cramer <pg@fastcrypt.com>

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