Skip to content

Commit 5ec61f4

Browse files
author
Barry Lind
committed
Fixes bug where join to pg_description was incorrect. Also modifies the
regression test to test for this case. Patch submitted by Kris Jurka. Modified Files: jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
1 parent ad18b10 commit 5ec61f4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
19881988
" END "+
19891989
" AS TABLE_TYPE, d.description AS REMARKS "+
19901990
" FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c "+
1991-
" LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid) "+
1991+
" LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) "+
19921992
" LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class') "+
19931993
" LEFT JOIN pg_catalog.pg_namespace dn ON (dn.oid=dc.relnamespace AND dn.nspname='pg_catalog') "+
19941994
" WHERE c.relnamespace = n.oid ";
@@ -2038,7 +2038,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
20382038
if (connection.haveMinimumServerVersion("7.1")) {
20392039
select = "SELECT NULL AS TABLE_CAT, NULL AS TABLE_SCHEM, c.relname AS TABLE_NAME, "+tableType+" AS TABLE_TYPE, d.description AS REMARKS "+
20402040
" FROM pg_class c "+
2041-
" LEFT JOIN pg_description d ON (c.oid=d.objoid) "+
2041+
" LEFT JOIN pg_description d ON (c.oid=d.objoid AND d.objsubid = 0) "+
20422042
" LEFT JOIN pg_class dc ON (d.classoid = dc.oid AND dc.relname='pg_class') "+
20432043
" WHERE true ";
20442044
} else {

src/interfaces/jdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* PS: Do you know how difficult it is to type on a train? ;-)
1111
*
12-
* $Id: DatabaseMetaDataTest.java,v 1.15 2002/10/01 00:39:02 davec Exp $
12+
* $Id: DatabaseMetaDataTest.java,v 1.16 2002/11/11 07:11:12 barry Exp $
1313
*/
1414

1515
public class DatabaseMetaDataTest extends TestCase
@@ -28,6 +28,11 @@ protected void setUp() throws Exception
2828
{
2929
con = TestUtil.openDB();
3030
TestUtil.createTable( con, "testmetadata", "id int4, name text, updated timestamp" );
31+
Statement stmt = con.createStatement();
32+
//we add the following comments to ensure the joins to the comments
33+
//are done correctly. This ensures we correctly test that case.
34+
stmt.execute("comment on table testmetadata is 'this is a table comment'");
35+
stmt.execute("comment on column testmetadata.id is 'this is a column comment'");
3136
}
3237
protected void tearDown() throws Exception
3338
{
@@ -44,12 +49,14 @@ public void testTables()
4449
DatabaseMetaData dbmd = con.getMetaData();
4550
assertNotNull(dbmd);
4651

47-
ResultSet rs = dbmd.getTables( null, null, "test%", new String[] {"TABLE"});
52+
ResultSet rs = dbmd.getTables( null, null, "testmetadat%", new String[] {"TABLE"});
4853
assertTrue( rs.next() );
4954
String tableName = rs.getString("TABLE_NAME");
5055
assertTrue( tableName.equals("testmetadata") );
5156
String tableType = rs.getString("TABLE_TYPE");
5257
assertTrue( tableType.equals("TABLE") );
58+
//There should only be one row returned
59+
assertTrue( "getTables() returned too many rows", rs.next() == false);
5360
rs.close();
5461

5562
rs = dbmd.getColumns("", "", "test%", "%" );

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy