Skip to content

Commit 879639b

Browse files
committed
This patch for the 7.0.2 JDBC interface addresses four issues I
encountered while getting my reporting tool up and running with the driver. All changes are in the DatabaseMetaData class. Problem: The getDatabaseProductVersion() method was returning "6.5.2" Resolution: Changed it to return "7.0.2" Problem: A call to getTables() with an unsupported table type (in the String array) resulted in a malformed SQL statement and subsequent parsing error Resolution: Unsupported table types are now ignored without error Problem: In a getTables() call, tables and views were both returned by the "TABLE" table type, and the "VIEW" table type was unsupported Resolution: Changed the "TABLE" type to return only physical tables and added support for the "VIEW" table type (returning only views) Problem: The getIdentifierQuoteString() method was returning null Resolution: This method now returns a double-quote Christopher Cain
1 parent 0ba0e32 commit 879639b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public String getDatabaseProductName() throws SQLException
179179
*/
180180
public String getDatabaseProductVersion() throws SQLException
181181
{
182-
return ("6.5.2");
182+
return ("7.0.2");
183183
}
184184

185185
/**
@@ -363,7 +363,7 @@ public boolean storesMixedCaseQuotedIdentifiers() throws SQLException
363363
*/
364364
public String getIdentifierQuoteString() throws SQLException
365365
{
366-
return null;
366+
return "\"";
367367
}
368368

369369
/**
@@ -1654,10 +1654,10 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
16541654
StringBuffer sql = new StringBuffer("select relname,oid from pg_class where (");
16551655
boolean notFirst=false;
16561656
for(int i=0;i<types.length;i++) {
1657-
if(notFirst)
1658-
sql.append(" or ");
16591657
for(int j=0;j<getTableTypes.length;j++)
16601658
if(getTableTypes[j][0].equals(types[i])) {
1659+
if(notFirst)
1660+
sql.append(" or ");
16611661
sql.append(getTableTypes[j][1]);
16621662
notFirst=true;
16631663
}
@@ -1706,7 +1706,8 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17061706
//
17071707
// IMPORTANT: the query must be enclosed in ( )
17081708
private static final String getTableTypes[][] = {
1709-
{"TABLE", "(relkind='r' and relname !~ '^pg_' and relname !~ '^xinv')"},
1709+
{"TABLE", "(relkind='r' and relhasrules='f' and relname !~ '^pg_' and relname !~ '^xinv')"},
1710+
{"VIEW", "(relkind='r' and relhasrules='t' and relname !~ '^pg_' and relname !~ '^xinv')"},
17101711
{"INDEX", "(relkind='i' and relname !~ '^pg_' and relname !~ '^xinx')"},
17111712
{"LARGE OBJECT", "(relkind='r' and relname ~ '^xinv')"},
17121713
{"SEQUENCE", "(relkind='S' and relname !~ '^pg_')"},
@@ -1717,7 +1718,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17171718
// These are the default tables, used when NULL is passed to getTables
17181719
// The choice of these provide the same behaviour as psql's \d
17191720
private static final String defaultTableTypes[] = {
1720-
"TABLE","INDEX","SEQUENCE"
1721+
"TABLE","VIEW","INDEX","SEQUENCE"
17211722
};
17221723

17231724
/**

src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public String getDatabaseProductName() throws SQLException
179179
*/
180180
public String getDatabaseProductVersion() throws SQLException
181181
{
182-
return ("6.5.2");
182+
return ("7.0.2");
183183
}
184184

185185
/**
@@ -363,7 +363,7 @@ public boolean storesMixedCaseQuotedIdentifiers() throws SQLException
363363
*/
364364
public String getIdentifierQuoteString() throws SQLException
365365
{
366-
return null;
366+
return "\"";
367367
}
368368

369369
/**
@@ -1654,10 +1654,10 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
16541654
StringBuffer sql = new StringBuffer("select relname,oid from pg_class where (");
16551655
boolean notFirst=false;
16561656
for(int i=0;i<types.length;i++) {
1657-
if(notFirst)
1658-
sql.append(" or ");
16591657
for(int j=0;j<getTableTypes.length;j++)
16601658
if(getTableTypes[j][0].equals(types[i])) {
1659+
if(notFirst)
1660+
sql.append(" or ");
16611661
sql.append(getTableTypes[j][1]);
16621662
notFirst=true;
16631663
}
@@ -1706,7 +1706,8 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17061706
//
17071707
// IMPORTANT: the query must be enclosed in ( )
17081708
private static final String getTableTypes[][] = {
1709-
{"TABLE", "(relkind='r' and relname !~ '^pg_' and relname !~ '^xinv')"},
1709+
{"TABLE", "(relkind='r' and relhasrules='f' and relname !~ '^pg_' and relname !~ '^xinv')"},
1710+
{"VIEW", "(relkind='r' and relhasrules='t' and relname !~ '^pg_' and relname !~ '^xinv')"},
17101711
{"INDEX", "(relkind='i' and relname !~ '^pg_' and relname !~ '^xinx')"},
17111712
{"LARGE OBJECT", "(relkind='r' and relname ~ '^xinv')"},
17121713
{"SEQUENCE", "(relkind='S' and relname !~ '^pg_')"},
@@ -1717,7 +1718,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17171718
// These are the default tables, used when NULL is passed to getTables
17181719
// The choice of these provide the same behaviour as psql's \d
17191720
private static final String defaultTableTypes[] = {
1720-
"TABLE","INDEX","SEQUENCE"
1721+
"TABLE","VIEW","INDEX","SEQUENCE"
17211722
};
17221723

17231724
/**

0 commit comments

Comments
 (0)