Skip to content

Commit 7c55390

Browse files
author
Dave Cramer
committed
schema awareness patch provided by Kris Jurka
1 parent 2a1e4a9 commit 7c55390

File tree

9 files changed

+1353
-896
lines changed

9 files changed

+1353
-896
lines changed

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.postgresql.util.*;
1515

1616

17-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.9 2002/09/11 05:38:44 barry Exp $
17+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.10 2002/10/01 00:39:01 davec Exp $
1818
* This class defines methods of the jdbc1 specification. This class is
1919
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
2020
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -1147,6 +1147,11 @@ public String getDBVersionNumber()
11471147
return dbVersionNumber;
11481148
}
11491149

1150+
/**
1151+
* Is the server we are connected to running at least this version?
1152+
* This comparison method will fail whenever a major or minor version
1153+
* goes to two digits (10.3.0) or (7.10.1).
1154+
*/
11501155
public boolean haveMinimumServerVersion(String ver) throws SQLException
11511156
{
11521157
return (getDBVersionNumber().compareTo(ver) >= 0);
@@ -1184,16 +1189,29 @@ public int getSQLType(int oid) throws SQLException
11841189
// it's not in the cache, so perform a query, and add the result to the cache
11851190
if (sqlType == null)
11861191
{
1187-
ResultSet result = ExecSQL("select typname from pg_type where oid = " + oid);
1188-
if (((AbstractJdbc1ResultSet)result).getColumnCount() != 1 || ((AbstractJdbc1ResultSet)result).getTupleCount() != 1)
1189-
throw new PSQLException("postgresql.unexpected");
1190-
result.next();
1191-
String pgType = result.getString(1);
1192+
String pgType;
1193+
// The opaque type does not exist in the system catalogs.
1194+
if (oid == 0) {
1195+
pgType = "opaque";
1196+
} else {
1197+
String sql;
1198+
if (haveMinimumServerVersion("7.3")) {
1199+
sql = "SELECT typname FROM pg_catalog.pg_type WHERE oid = " +oid;
1200+
} else {
1201+
sql = "SELECT typname FROM pg_type WHERE oid = " +oid;
1202+
}
1203+
ResultSet result = ExecSQL(sql);
1204+
if (((AbstractJdbc1ResultSet)result).getColumnCount() != 1 || ((AbstractJdbc1ResultSet)result).getTupleCount() != 1) {
1205+
throw new PSQLException("postgresql.unexpected");
1206+
}
1207+
result.next();
1208+
pgType = result.getString(1);
1209+
result.close();
1210+
}
11921211
Integer iOid = new Integer(oid);
1193-
sqlType = new Integer(getSQLType(result.getString(1)));
1212+
sqlType = new Integer(getSQLType(pgType));
11941213
sqlTypeCache.put(iOid, sqlType);
11951214
pgTypeCache.put(iOid, pgType);
1196-
result.close();
11971215
}
11981216

11991217
return sqlType.intValue();
@@ -1217,8 +1235,13 @@ public int getPGType(String typeName) throws SQLException
12171235
else
12181236
{
12191237
// it's not in the cache, so perform a query, and add the result to the cache
1220-
ResultSet result = ExecSQL("select oid from pg_type where typname='"
1221-
+ typeName + "'");
1238+
String sql;
1239+
if (haveMinimumServerVersion("7.3")) {
1240+
sql = "SELECT oid FROM pg_catalog.pg_type WHERE typname='" + typeName + "'";
1241+
} else {
1242+
sql = "SELECT oid FROM pg_type WHERE typname='" + typeName + "'";
1243+
}
1244+
ResultSet result = ExecSQL(sql);
12221245
if (((AbstractJdbc1ResultSet)result).getColumnCount() != 1 || ((AbstractJdbc1ResultSet)result).getTupleCount() != 1)
12231246
throw new PSQLException("postgresql.unexpected");
12241247
result.next();

0 commit comments

Comments
 (0)