Thread: RE: JDBC driver writes binary data ONLY as Large Obj ect

RE: JDBC driver writes binary data ONLY as Large Obj ect

From
Peter Mount
Date:
The problem here is that there is no metadata available to check.

If the backend was able to precompile the query, then we would know the
column type, but as it stands currently there is no way of finding out what
the column type is.

Peter

--
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council


-----Original Message-----
From: Bill [mailto:bouma@cplane.com]
Sent: Tuesday, August 01, 2000 8:37 PM
To: pgsql-interfaces@postgresql.org
Subject: [INTERFACES] JDBC driver writes binary data ONLY as Large
Object


The problem is that PreparedStatement.setBytes() only writes Large
Objects.  It should do something like ResultSet.getBytes(), which
checks the column meta-data to see if the column holds an OID or
not, then do the right thing based on that.

Bill <bouma@cplane.com>

-------------------------------------------------

.../postgresql-7.0.2/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatem
ent.java

/**  * Set a parameter to a Java array of bytes.  The driver converts this  * to a SQL VARBINARY or LONGVARBINARY
(dependingon the argument's  * size relative to the driver's limits on VARBINARYs) when it sends  * it to the database.
*  * <p>Implementation note:  * <br>With org.postgresql, this creates a large object, and stores the  * objects oid in
thiscolumn.  *  * @param parameterIndex the first parameter is 1...  * @param x the parameter value  * @exception
SQLExceptionif a database access error occurs  */ public void setBytes(int parameterIndex, byte x[]) throws
SQLException{   LargeObjectManager lom = connection.getLargeObjectAPI();   int oid = lom.create();   LargeObject lob =
lom.open(oid);  lob.write(x);   lob.close();   setInt(parameterIndex,oid); }
 


Re: JDBC driver writes binary data ONLY as Large Object

From
Bill
Date:
Peter Mount wrote:

> The problem here is that there is no metadata available to check.
>
> If the backend was able to precompile the query, then we would know the
> column type, but as it stands currently there is no way of finding out what
> the column type is.
>
> Peter

Ok.  Suppose there was metadata available.  How would you
rewrite the function PreparedStatement.writeBytes() such that
it writes the bytes directly into the column?  Since that class
does everything through heavy use of String manipulation, I
can't see how to do it.  Is there a way?  I tried this:
 public void setBytes(int parameterIndex, byte x[]) throws SQLException {     set(parameterIndex, new String(x)); }

It barfed.

Bill