Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSsDE-0001Fm-Py for pgsql-jdbc@arkaria.postgresql.org; Thu, 28 Jul 2016 20:47:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bSsDE-0007Vi-C1 for pgsql-jdbc@arkaria.postgresql.org; Thu, 28 Jul 2016 20:47:24 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bSsCk-0006wJ-2W for pgsql-jdbc@postgresql.org; Thu, 28 Jul 2016 20:46:54 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bSsCh-0003Jc-CY for pgsql-jdbc@postgresql.org; Thu, 28 Jul 2016 20:46:52 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1bSsCe-0005TD-Ae for pgsql-jdbc@postgresql.org; Thu, 28 Jul 2016 22:46:48 +0200 Received: from ppp-93-104-119-86.dynamic.mnet-online.de ([93.104.119.86]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 Jul 2016 22:46:48 +0200 Received: from spam_eater by ppp-93-104-119-86.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 Jul 2016 22:46:48 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: ResultSet.getClob() causing problems when used with JPA's @Lob Date: Thu, 28 Jul 2016 22:46:22 +0200 Lines: 57 Message-ID: References: <201102070001.22259.andreak@officenet.no> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-93-104-119-86.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: X-Pg-Spam-Score: -3.9 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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