getObject(<oid>) returns integer instead of LargeObject handle ?

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

getObject(<oid>) returns integer instead of LargeObject handle ?

От:
Marc Herbert <Marc.Herbert@emicnetworks.com>
Дата:
Hi,

 Is there some good reason for getObject() to return the
bare oid integer instead of the actual LargeObject handle ?

 I slightly modified the driver as below and it fixed my Blob issues
without any other side-effects. Would have some extensive testing
shown some problems I missed ?  Sorry for not being very familiar with
Postgres' oids.

Thanks in advance.

Cheers,

Marc.


Index: postgresql/jdbc2/TypeInfoCache.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/TypeInfoCache.java,v
retrieving revision 1.1
diff -u -r1.1 TypeInfoCache.java
--- postgresql/jdbc2/TypeInfoCache.java	10 Apr 2005 21:54:16 -0000	1.1
+++ postgresql/jdbc2/TypeInfoCache.java	22 Jul 2005 13:45:35 -0000
@@ -51,7 +51,7 @@
     private static Object types[][] = {
         {"int2", new Integer(Oid.INT2), new Integer(Types.SMALLINT), "java.lang.Short"},
         {"int4", new Integer(Oid.INT4), new Integer(Types.INTEGER), "java.lang.Integer"},
-        {"oid", new Integer(Oid.OID), new Integer(Types.INTEGER), "java.lang.Integer"},
+        {"oid", new Integer(Oid.OID), new Integer(Types.BLOB), "java.sql.Blob"},
         {"int8", new Integer(Oid.INT8), new Integer(Types.BIGINT), "java.lang.Long"},
         {"money", new Integer(Oid.MONEY), new Integer(Types.DOUBLE), "java.lang.Double"},
         {"numeric", new Integer(Oid.NUMERIC), new Integer(Types.NUMERIC), "java.math.BigDecimal"},

Re: getObject(<oid>) returns integer instead of LargeObject

От:
Kris Jurka <books@ejurka.com>
Дата:


On Fri, 22 Jul 2005, Marc Herbert wrote:

>  Is there some good reason for getObject() to return the
> bare oid integer instead of the actual LargeObject handle ?

This makes the assumption that the only use of oids is for large objects.  
What if someone wrote SELECT oid,relname FROM pg_class?

Kris Jurka

Re: getObject(<oid>) returns integer instead of LargeObject

От:
Marc Herbert <Marc.Herbert@emicnetworks.com>
Дата:
On Fri, Jul 22, 2005 at 01:41:19PM -0500, Kris Jurka wrote:
> 
> 
> On Fri, 22 Jul 2005, Marc Herbert wrote:
> 
> >  Is there some good reason for getObject() to return the
> > bare oid integer instead of the actual LargeObject handle ?
> 
> This makes the assumption that the only use of oids is for large objects.  
> What if someone wrote SELECT oid,relname FROM pg_class?

Thanks for answering.

What would you recommend to unambiguously identify a Blob column in a
arbitrary ResultSet, using only JDBC?

For instance could you trust
Types.BLOB == rs.getMetaData.getColumnType() in every case?
Is there any other way?

Would it depend on the latest version of the driver/database?

Thanks in advance for you help!


PS: why do LOBs seem to use regular oids instead of some other less
ambiguous say, "loid" ?

Re: getObject(<oid>) returns integer instead of LargeObject

От:
Oliver Jowett <oliver@opencloud.com>
Дата:
Marc Herbert wrote:

> What would you recommend to unambiguously identify a Blob column in a
> arbitrary ResultSet, using only JDBC?

I don't think there is any way to do this in general, via JDBC or any 
other interface; you need schema-specific knowledge to work out which 
oid columns refer to LOs and which refer to a different sort of oid 
somewhere else.

The actual LO interface itself just looks like "create LO" -> "ok, 
here's an oid identifying it"; there's nothing that ties the column you 
happen to use to store that oid to the LO itself. See 
http://www.postgresql.org/docs/8.0/static/largeobjects.html for more 
details.

For comparison, contrib/vacuumlo assumes that any (non-system-generated) 
oid column in the system could potentially reference a LO (in GC-speak 
it's a conservative collector).

> PS: why do LOBs seem to use regular oids instead of some other less
> ambiguous say, "loid" ?

It's just an artifact of the implementation AFAIK.

-O
FAQ