From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: ResultSet.getClob() causing problems when used with JPA's @Lob
Date: Thu, 28 Jul 2016 22:46:22 +0200
Message-ID: <nndqvd$1al$1@ger.gmane.org> (raw)
In-Reply-To: <nndpn0$jv4$2@ger.gmane.org>
References: <201102070001.22259.andreak@officenet.no>
<nmnoj4$ouq$1@ger.gmane.org>
<nnb1h7$hgm$1@ger.gmane.org>
<CAB=Je-FbszwjAFVYfr+DiGgS8dOhsOFTGK65=d7VyjPAHdnyvQ@mail.gmail.com>
<nndpn0$jv4$2@ger.gmane.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
Thomas Kellerer schrieb am 28.07.2016 um 22:24:
> Vladimir Sitnikov schrieb am 27.07.2016 um 21:58:
>>
>> I think something similar is needed for PgPreparedStatement as well, but I did not find a way to check
>> the type of a column the way it's done in PgResultSet. It seems that ParameterList.getTypeOIDs()
>> would provide that information, but I don't know how to use that. If someone points me in the right
>> direction I can add that as well.
>>
>>
>> I'm not yet ready to answer that.
>>
>
> It would be nice if someone else could point me in the right direction, because I think
> that only a change to PreparedStatement would make that complete.
>
I wonder if something like this would be correct to detect the column type in PgPreparedStatement:
private boolean isBytea(int i) throws SQLException {
TypeInfo info = connection.getTypeInfo();
int columnOID = preparedParameters.getTypeOIDs()[i];
String pgType = info.getPGType(columnOID);
return "bytea".equals(pgType);
}
private boolean isVarchar(int i) throws SQLException {
TypeInfo info = connection.getTypeInfo();
int columnOID = preparedParameters.getTypeOIDs()[i];
String pgType = info.getPGType(columnOID);
return "text".equals(pgType) ||
"varchar".equals(pgType) ||
"character varying".equals(pgType) ||
"char".equals(pgType);
}
I chose to compare the Postgres Names rather than the java.sql.Type constants because it seems
that TypeInfoCache will send a SQL query to the backend (at least once) to get that mapping.
I am not sure if "character varying" will ever be needed. TypeInfoCache does not have that in its internal array
where oids are mapped to type names.
and then in the setClob() method:
if (isVarchar(i)) {
setString(i, x.getSubString(1, (int)x.length()));
return;
}
and for setBlob() the similar thing:
if (isBytea(i)) {
setBytes(i, x.getBytes(1, (int)x.length()));
return;
}
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: ResultSet.getClob() causing problems when used with JPA's @Lob
In-Reply-To: <nndqvd$1al$1@ger.gmane.org>
References: <201102070001.22259.andreak@officenet.no> <nmnoj4$ouq$1@ger.gmane.org> <nnb1h7$hgm$1@ger.gmane.org> <CAB=Je-FbszwjAFVYfr+DiGgS8dOhsOFTGK65=d7VyjPAHdnyvQ@mail.gmail.com> <nndpn0$jv4$2@ger.gmane.org> <nndqvd$1al$1@ger.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox