Received: from maia.hub.org (maia-1.hub.org [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 56F2F63249B for ; Thu, 29 Apr 2010 09:50:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 23482-01-5 for ; Thu, 29 Apr 2010 12:50:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zimbra.tecnoteca.it (dns.tecnoteca.it [80.20.200.51]) by mail.postgresql.org (Postfix) with ESMTP id 9A78D6345DF for ; Thu, 29 Apr 2010 09:49:48 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by zimbra.tecnoteca.it (Postfix) with ESMTP id 33FD026A69 for ; Thu, 29 Apr 2010 14:49:30 +0200 (CEST) X-Virus-Scanned: amavisd-new at Received: from zimbra.tecnoteca.it ([127.0.0.1]) by localhost (zimbra.tecnoteca.it [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ruVIVpCbRtpu for ; Thu, 29 Apr 2010 14:49:29 +0200 (CEST) Received: from zimbra.tecnoteca.it (zimbra.tecnoteca.it [192.168.1.223]) by zimbra.tecnoteca.it (Postfix) with ESMTP id DC8D126A68 for ; Thu, 29 Apr 2010 14:49:29 +0200 (CEST) Date: Thu, 29 Apr 2010 14:49:29 +0200 (CEST) From: Paolo Ambrosio To: pgsql-jdbc@postgresql.org Message-ID: <21934325.2411272545369820.JavaMail.root@zimbra> In-Reply-To: <29382200.2391272545227538.JavaMail.root@zimbra> Subject: getSuperTables MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_75_12169702.1272545369817" X-Originating-IP: [192.168.1.200] X-Mailer: Zimbra 5.0.10_GA_2638.openSUSE_10.2 (ZimbraWebClient - FF3.0 (Linux)/5.0.10_GA_2638.openSUSE_10.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-10 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201004/70 X-Sequence-Number: 20481 ------=_Part_75_12169702.1272545369817 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 ------=_Part_75_12169702.1272545369817 Content-Type: text/x-patch; name=pgjdbc-getsupertables.diff Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=pgjdbc-getsupertables.diff 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; < * null 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) > { > } > } > } ------=_Part_75_12169702.1272545369817--