14
14
import org .postgresql .util .*;
15
15
16
16
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 $
18
18
* This class defines methods of the jdbc1 specification. This class is
19
19
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
20
20
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -1147,6 +1147,11 @@ public String getDBVersionNumber()
1147
1147
return dbVersionNumber ;
1148
1148
}
1149
1149
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
+ */
1150
1155
public boolean haveMinimumServerVersion (String ver ) throws SQLException
1151
1156
{
1152
1157
return (getDBVersionNumber ().compareTo (ver ) >= 0 );
@@ -1184,16 +1189,29 @@ public int getSQLType(int oid) throws SQLException
1184
1189
// it's not in the cache, so perform a query, and add the result to the cache
1185
1190
if (sqlType == null )
1186
1191
{
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
+ }
1192
1211
Integer iOid = new Integer (oid );
1193
- sqlType = new Integer (getSQLType (result . getString ( 1 ) ));
1212
+ sqlType = new Integer (getSQLType (pgType ));
1194
1213
sqlTypeCache .put (iOid , sqlType );
1195
1214
pgTypeCache .put (iOid , pgType );
1196
- result .close ();
1197
1215
}
1198
1216
1199
1217
return sqlType .intValue ();
@@ -1217,8 +1235,13 @@ public int getPGType(String typeName) throws SQLException
1217
1235
else
1218
1236
{
1219
1237
// 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 );
1222
1245
if (((AbstractJdbc1ResultSet )result ).getColumnCount () != 1 || ((AbstractJdbc1ResultSet )result ).getTupleCount () != 1 )
1223
1246
throw new PSQLException ("postgresql.unexpected" );
1224
1247
result .next ();
0 commit comments