pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedgetSuperTables
2+ messages / 2 participants
[nested] [flat]
* getSuperTables
@ 2010-04-29 12:49 Paolo Ambrosio <p.ambrosio@tecnoteca.it>
2010-04-30 22:01 ` Re: getSuperTables Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Ambrosio @ 2010-04-29 12:49 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
I need the JDBC3 method getSuperTables for a software I'm working on.
I have implemented it using syntax and coding guidelines as close as possible to the rest of the surronding code. I tried it with PostgreSQL 8.4, and I don't know the structure of the catalog for version 7, so it throws an exception if the server version not at least 8.0.
I am attaching the patch and I would appreciate if someone could take a look at it, and perhaps commit it into the cvs repository.
Regards,
Paolo
Attachments:
pgjdbc-getsupertables.diff (text/x-patch, 3.8K) download
Index: org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc3/AbstractJdbc3DatabaseMetaData.java,v
retrieving revision 1.14
diff -r1.14 AbstractJdbc3DatabaseMetaData.java
153,154c153,154
< * @param catalog a catalog name; "" retrieves those without a catalog;
< * <code>null</code> means drop catalog name from the selection criteria
---
> * @param catalog a catalog name; For org.postgresql, this is ignored, and
> * should be set to null
166c166,191
< throw org.postgresql.Driver.notImplemented(this.getClass(), "getSuperTables(String,String,String,String)");
---
> String select;
> String orderby;
> if (connection.haveMinimumServerVersion("8.0"))
> {
> select = "SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, t.relname AS TABLE_NAME, " +
> " st.relname AS SUPERTABLE_NAME " +
> " FROM pg_catalog.pg_inherits AS i " +
> " JOIN pg_catalog.pg_class AS t ON i.inhrelid = t.oid " +
> " JOIN pg_catalog.pg_namespace AS n ON t.relnamespace = n.oid " +
> " JOIN pg_catalog.pg_class AS st ON i.inhparent = st.oid";
> if (schemaPattern != null && !"".equals(schemaPattern))
> {
> select += " AND n.nspname LIKE '" + escapeQuotes(schemaPattern) + "' ";
> }
> if (tableNamePattern != null)
> {
> select += " AND t.relname LIKE '" + escapeQuotes(tableNamePattern) + "' ";
> }
> orderby = " ORDER BY TABLE_SCHEM,TABLE_NAME ";
> }
> else
> {
> throw org.postgresql.Driver.notImplemented(this.getClass(), "getSuperTables(String,String,String,String)");
> }
> String sql = select + orderby;
> return createMetaDataStatement().executeQuery(sql);
Index: org/postgresql/test/jdbc3/DatabaseMetaDataTest.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/test/jdbc3/DatabaseMetaDataTest.java,v
retrieving revision 1.2
diff -r1.2 DatabaseMetaDataTest.java
12a13
> import org.postgresql.util.PSQLException;
28a30
> Statement stmt = _conn.createStatement();
30d31
< Statement stmt = _conn.createStatement();
33a35,36
> stmt.execute("CREATE TABLE supertab ()");
> stmt.execute("CREATE TABLE subtab () INHERITS (supertab)");
37a41,43
> Statement stmt = _conn.createStatement();
> stmt.execute("DROP TABLE subtab");
> stmt.execute("DROP TABLE supertab");
39d44
< Statement stmt = _conn.createStatement();
60a66,95
> public void testGetSuperTables() throws Exception
> {
> DatabaseMetaData dbmd = _conn.getMetaData();
> if (TestUtil.haveMinimumServerVersion(_conn, "8.0"))
> {
> ResultSet rs;
> rs = dbmd.getSuperTables(null, null, null);
> assertTrue(rs.next());
> assertEquals(null, rs.getString("TABLE_CAT"));
> assertEquals("public", rs.getString("TABLE_SCHEM"));
> assertEquals("subtab", rs.getString("TABLE_NAME"));
> assertEquals("supertab", rs.getString("SUPERTABLE_NAME"));
> assertFalse(rs.next());
> rs = dbmd.getSuperTables(null, "%lic", "sub%");
> assertTrue(rs.next());
> rs = dbmd.getSuperTables(null, null, "sup%");
> assertFalse(rs.next());
> }
> else
> {
> try
> {
> dbmd.getSuperTables(null, null, null);
> fail();
> }
> catch (PSQLException e)
> {
> }
> }
> }
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: getSuperTables
2010-04-29 12:49 getSuperTables Paolo Ambrosio <p.ambrosio@tecnoteca.it>
@ 2010-04-30 22:01 ` Kris Jurka <books@ejurka.com>
0 siblings, 0 replies; 2+ messages in thread
From: Kris Jurka @ 2010-04-30 22:01 UTC (permalink / raw)
To: Paolo Ambrosio <p.ambrosio@tecnoteca.it>; +Cc: pgsql-jdbc
On Thu, 29 Apr 2010, Paolo Ambrosio wrote:
> I need the JDBC3 method getSuperTables for a software I'm working on.
>
> I am attaching the patch and I would appreciate if someone could take a
> look at it, and perhaps commit it into the cvs repository.
>
The JDBC javadoc for getSuperTables [1] is kind of odd. It says:
Supertables have to be defined in the same catalog and schema
as the sub tables. Therefore, the type description does not
need to include this information for the supertable.
This seems like an odd restriction based on some other database, but it is
not the case in PG. I guess we have to follow it though because there
really isn't any place to indicate the schema if it isn't the same as the
sub-table. Please update your patch to include this restriction.
Also your patch should be in context diff format (use "cvs diff -c").
Kris Jurka
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2010-04-30 22:01 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-04-29 12:49 getSuperTables Paolo Ambrosio <p.ambrosio@tecnoteca.it>
2010-04-30 22:01 ` Kris Jurka <books@ejurka.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