From: | Tore Halset <halset(at)pvv(dot)ntnu(dot)no> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | the good old getObject(<oid>) issue.. |
Date: | 2006-09-22 13:19:19 |
Message-ID: | AF59A25B-E223-46CD-A627-93E3E42E6FC1@pvv.ntnu.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hello.
I have read all the stuff about this issue on this mail list and
think I understand the issue. However, I desperately want to be able
to get a oid blob with getObject()..
If I have control I do getInt(oidcolumn) if I want the oid value and
getBlob(oidcolumn) if I want a blob. Sometimes I do not have control
as some other product may use getObject and I am not able to switch
from oid to bytea.
I found a real hacky solution for this situation. It defaults to
getBlob and switch to getInt if getBlob throws a PSQLException. I
know this kind of mess could not go into the main source tree, but I
am posting it here for archiving..
In AbstractJdbc2ResultSet.getObject(int) before internalGetObject:
// hack to handle getObject() on an oid with a blob
if (field.getOID() == Oid.OID) {
if (Driver.logDebug) {
Driver.debug("getObject of oid column. will try
getBlob first. column "
+ field.getColumnLabel());
}
try {
return getBlob(columnIndex);
} catch (PSQLException e) {
if (Driver.logDebug) {
String msg = "getObject(oid): getBlob failed.
fallback to getInt for column "
+ field.getColumnLabel() + ". " +
e.getMessage();
Driver.debug(msg);
}
return getInt(columnIndex);
}
}
Possible improvements:
* make the lob stuff throw a PSQLException subclass that this code
could use instead.
* control this behaviour with a user settable jdbc driver parameter
- Tore.
From | Date | Subject | |
---|---|---|---|
Next Message | Markus Schaber | 2006-09-22 13:23:49 | Re: ResultSetMetaData.getTableName() == null |
Previous Message | Alex Stienstra | 2006-09-22 06:49:44 | Re: ResultSetMetaData.getTableName() == null |