1414import 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()
11471147return 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+ */
11501155public boolean haveMinimumServerVersion (String ver )throws SQLException
11511156{
11521157return (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
11851190if (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+ }
11921211Integer iOid =new Integer (oid );
1193- sqlType =new Integer (getSQLType (result . getString ( 1 ) ));
1212+ sqlType =new Integer (getSQLType (pgType ));
11941213sqlTypeCache .put (iOid ,sqlType );
11951214pgTypeCache .put (iOid ,pgType );
1196- result .close ();
11971215}
11981216
11991217return sqlType .intValue ();
@@ -1217,8 +1235,13 @@ public int getPGType(String typeName) throws SQLException
12171235else
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 );
12221245if (((AbstractJdbc1ResultSet )result ).getColumnCount () !=1 || ((AbstractJdbc1ResultSet )result ).getTupleCount () !=1 )
12231246throw new PSQLException ("postgresql.unexpected" );
12241247result .next ();