Обсуждение: the good old getObject() issue..

Поиск
Список
Период
Сортировка

the good old getObject() issue..

От
Tore Halset
Дата:
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.