Re: [Patch] JDBC3 Blob support

Lists: pgsql-jdbc
From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-02-19 20:15:29
Message-ID: Pine.BSO.4.56.0502191512160.18612@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Sat, 19 Feb 2005, Michael Barker wrote:

> I have attached a patch that provides support for JDBC 3 Blobs for the
> PostgreSQL driver.
>
> JUnit tests are included. The only method that is not implemented is
> truncate(). I couldn't find a simple efficient method for doing this
> via the LargeObject API.
>

You have not included the unit tests. What about implemeting these
methods for CLOB at the same time? They're pretty much identical.

You have included your username and password in build.properties though,
you can put these values in a file called build.local.properties and they
will not show up in diffs.

Kris Jurka


From: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: [Patch] JDBC3 Blob support
Date: 2005-02-20 01:58:14
Message-ID: 1108864694.5883.5.camel@corona
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi,

I have attached a patch that provides support for JDBC 3 Blobs for the
PostgreSQL driver.

JUnit tests are included. The only method that is not implemented is
truncate(). I couldn't find a simple efficient method for doing this
via the LargeObject API.

I am posting off list. Please email me direct if you have any queries.

Regards,
Michael Barker

Attachment Content-Type Size
blob-support.patch text/x-patch 6.9 KB

From: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-03-05 04:39:17
Message-ID: 1109997557.3838.1.camel@corona
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Attached is a patch for Blob and Clob support with JUnits.

Regards,
Michael Barker.

On Sat, 2005-02-19 at 15:15 -0500, Kris Jurka wrote:
>
> On Sat, 19 Feb 2005, Michael Barker wrote:
>
> > I have attached a patch that provides support for JDBC 3 Blobs for the
> > PostgreSQL driver.
> >
> > JUnit tests are included. The only method that is not implemented is
> > truncate(). I couldn't find a simple efficient method for doing this
> > via the LargeObject API.
> >
>
> You have not included the unit tests. What about implemeting these
> methods for CLOB at the same time? They're pretty much identical.
>
> You have included your username and password in build.properties though,
> you can put these values in a file called build.local.properties and they
> will not show up in diffs.
>
> Kris Jurka
>

Attachment Content-Type Size
blob-clob.patch.gz application/x-gzip 5.8 KB

From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-03-20 22:39:46
Message-ID: Pine.BSO.4.56.0503201658370.32696@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Fri, 4 Mar 2005, Michael Barker wrote:

> Attached is a patch for Blob and Clob support with JUnits.
>

I've finally gotten around to reviewing this. The real problem is how to
deal with Clobs and encodings. PostgreSQL doesn't really have any
specific character large object support and the jdbc driver just
layers the Clob type on the existing binary large objects. From
the server's perspective it is all just binary data which makes
things like length return a number of bytes instead of the number
of characters, at least for a multibyte encoding.

As I see it we've got a number of poor options:
1) Always use a single byte encoding (like US-ASCII) for storing data even
though this cannot store all characters.
2) Always use a multibyte encoding (like UTF-8) for storing data even
though this will break many length/positioning methods.
3) Allow the user to select the encoding via a URL parameter.
4) Use the database's server encoding even though this won't always have a
JVM equivalent.
5) Use the JVM's encoding.

3) Seems like the only way to really allow a user to pick their poison.
Anyone else have an opinion? I suppose we could move a lot of the large
object exection from the server to the JDBC driver so it could correctly
count characters, but that'd we quite a performance hit.

I've attached the version of the patch that I've adjusted slightly and
pretty much ignores encoding entirely.

Finally some technical comments on the original patch:

You shouldn't throw a SQLException without a SQL State. To help enforce
this we throw org.postgresql.util.PSQLException that doesn't have a
constructor without a SQL state aregument.

In the unit tests you write:

if (rs.next()) {
// do something
} else {
assertFalse("Message", true);
}

We don't use assertFalse in order to retain compatibility with junit 3.7.
Also this is written more clearly as:

assertTrue(rs.next());
// do something

Kris Jurka

Attachment Content-Type Size
blobclob.patch.gz application/octet-stream 4.7 KB

From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
Cc: acoliver(at)jboss(dot)org, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-03-24 19:58:11
Message-ID: Pine.BSO.4.56.0503241438280.30237@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Wed, 23 Mar 2005, Michael Barker wrote:

> I will have a look at the patch over the weekend. When I wrote the CLOB
> stuff I set it up to always use a single byte encoding, except when using
> get/setCharacterStream. If a user required mulltibyte encodings then they
> should use the Reader/Writer combination exclusively.

AbstractJdbc2Clob.getSubString creates a String from bytes with no
encoding specified.

AbstractJdbc3Clob.setString(long, String, int, int) gets a String's bytes
with no encoding specified.

Even when the user wants a multibyte encoding they are stuck using the
JVM's default encoding because the Reader/Writer's are not created with an
encoding specified.

Yeah, it's a complicated issue. I know you were after just the BLOB part
and I pushed you into the CLOB part. No one else has any feedback, and no
matter what we do it won't be all that good, so maybe the smart thing to
do is just to abandon the CLOB part and just put the BLOB in by itself.
Not to discourage you if you really are interested in the CLOB part of it,
just letting you know that it's not a prerequisite for the BLOB part to
get in.

Kris Jurka


From: Vadim Nasardinov <vadimn(at)redhat(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: CLOB encoding (was: Re: [Patch] JDBC3 Blob support)
Date: 2005-03-24 21:40:15
Message-ID: 200503241640.15741@vadim.nasardinov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Thursday 24 March 2005 14:58, Kris Jurka wrote:
> and I pushed you into the CLOB part. No one else has any feedback

After reading your original comments in
http://archives.postgresql.org/pgsql-jdbc/2005-03/msg00167.php, I had
a couple of questions that I neglected to ask right away. If you
don't mind clarifying a couple of things for me, here they are:

* Did I understand correctly that the server does not have an
encoding associated with CLOB columns?

* How do other databases deal with this? Since I haven't touched
Oracle in a long time, I would appreciate it if someone could
refresh my recollection. Do Oracle's CLOBs know their encoding?
Do Oracle's dbms_lob functions respect the CLOB encoding?


From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
Cc: acoliver(at)jboss(dot)org, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-03-24 23:45:28
Message-ID: Pine.BSO.4.56.0503241844280.31387@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Thu, 24 Mar 2005, Michael Barker wrote:

> Yeah, you got me. My intent was to implement the above, but I kinda
> hacked in the CLOB stuff, as I was more interested in getting the BLOB
> support in place. If you would be willing to commit the BLOB pieces
> then it would be appreciated as this has the greatest benefit to the
> JBoss Mail project. I am still interested in doing the CLOB stuff as a
> have a picture of how to do it (though its not pretty), but would prefer
> it not to hold up the BLOB support. Would you like me to resubmit a
> BLOB patch w/JUnits?

I'll apply just the BLOB part of this while we decide what to do about
CLOBs.

Kris Jurka


From: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: acoliver(at)jboss(dot)org, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-03-25 07:42:19
Message-ID: 1111736540.3674.4.camel@corona
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Thu, 2005-03-24 at 14:58 -0500, Kris Jurka wrote:
>
> On Wed, 23 Mar 2005, Michael Barker wrote:
>
> > I will have a look at the patch over the weekend. When I wrote the CLOB
> > stuff I set it up to always use a single byte encoding, except when using
> > get/setCharacterStream. If a user required mulltibyte encodings then they
> > should use the Reader/Writer combination exclusively.
>
> AbstractJdbc2Clob.getSubString creates a String from bytes with no
> encoding specified.
>
> AbstractJdbc3Clob.setString(long, String, int, int) gets a String's bytes
> with no encoding specified.

Yeah, you got me. My intent was to implement the above, but I kinda
hacked in the CLOB stuff, as I was more interested in getting the BLOB
support in place. If you would be willing to commit the BLOB pieces
then it would be appreciated as this has the greatest benefit to the
JBoss Mail project. I am still interested in doing the CLOB stuff as a
have a picture of how to do it (though its not pretty), but would prefer
it not to hold up the BLOB support. Would you like me to resubmit a
BLOB patch w/JUnits?

>
> Even when the user wants a multibyte encoding they are stuck using the
> JVM's default encoding because the Reader/Writer's are not created with an
> encoding specified.
>
> Yeah, it's a complicated issue. I know you were after just the BLOB part
> and I pushed you into the CLOB part. No one else has any feedback, and no
> matter what we do it won't be all that good, so maybe the smart thing to
> do is just to abandon the CLOB part and just put the BLOB in by itself.
> Not to discourage you if you really are interested in the CLOB part of it,
> just letting you know that it's not a prerequisite for the BLOB part to
> get in.
>
> Kris Jurka
>

Mike.


From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Barker <mike(at)middlesoft(dot)co(dot)uk>
Cc: acoliver(at)jboss(dot)org, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [Patch] JDBC3 Blob support
Date: 2005-03-28 08:54:18
Message-ID: Pine.BSO.4.56.0503280353150.8879@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Thu, 24 Mar 2005, Kris Jurka wrote:
>
> On Thu, 24 Mar 2005, Michael Barker wrote:
>
> > Yeah, you got me. My intent was to implement the above, but I kinda
> > hacked in the CLOB stuff, as I was more interested in getting the BLOB
> > support in place. If you would be willing to commit the BLOB pieces
> > then it would be appreciated as this has the greatest benefit to the
> > JBoss Mail project. I am still interested in doing the CLOB stuff as a
> > have a picture of how to do it (though its not pretty), but would prefer
> > it not to hold up the BLOB support. Would you like me to resubmit a
> > BLOB patch w/JUnits?
>
> I'll apply just the BLOB part of this while we decide what to do about
> CLOBs.
>

OK, I've applied the BLOB part. I left in AbstractJdbc2BlobClob with the
assumption that the CLOB stuff will build upon it.

Kris Jurka