On 12 Jan 2004, Per-Olof Noren wrote:
> Hi Kris,
>
> On Tue, 2003-12-30 at 09:25, Kris Jurka wrote:
> > With the introduction of the V3 protocol in 7.4 it is now possible to
> > support the COPY protocol in the JDBC driver. Before it was impossible to
> > recover from errors and the Connection had to be abandoned. This patch
> > implements support for COPY based on the API proposed by Michael
> > Adler's original patch of about a year ago.
>
> This is great news, as I'm currently working on a project that could
> benefit from being able to run copy on a client machine.
> I have patched the driver from the 7.4.1 src distro with the patch and
> it compiled successfully.
>
> After giving it a spin (which actually failed due to another reason,
> more on that below) I have a little suggestion.
>
> Add CopyManager.copyIn(String tName, InputStream is, String delimiter);
>
> Or add Javadoc that clearly states that the query
> *MUST* be using "FROM STDIN" or the server will start looking locally
> for the file, giving an FileNotException.
I'm working on a new API that is more flexible in this and a number of
other regards. Something like this will probably get folded in.
> Ok, now to my litte trouble.
> The database is encoded in LATIN1 running on pgsql 7.4.1.
> I'm running the above code on a different machine running linux using
> locale "sv_SE". The file I'm trying to import is encoded in ISO-8859-1.
> Then running the above code I get the following error:
> org.postgresql.util.PSQLException: ERROR: could not convert UTF-8
> character 0x00f6 to ISO8859-1
>
> This must be the JVM's encoding being set to UTF-8, right?
> Or do I need to specify the encoding in the jdbc url or something?
>
As it stands now the JVM's encoding must be UTF-8 or you must do the
conversion to UTF-8 on your own. This is not good, but for the first pass
I wanted to focus on the copy protocol itself and left a number of user
interface features out.
The next version of this will allow you to specify some kind of recoding
to be done. Additionally it will provide support for a much friendlier
interface than an I/O Stream. Based on a suggestion from Oliver Jowett
I'm going to add an interface based on SQLInput/SQLOutput so an object can
easily read/write itself directly from/to a copy command so there isn't a
need to persist things to a Stream if your application doesn't want to.
Kris Jurka