Re: BUG #4866: ECPG and BYTEA - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject Re: BUG #4866: ECPG and BYTEA
Date
Msg-id 4A408DB8.3060109@enterprisedb.com
Whole thread Raw
In response to BUG #4866: ECPG and BYTEA  ("Rick Levine" <Richard_D_Levine@raytheon.com>)
Responses Re: BUG #4866: ECPG and BYTEA  (Richard D Levine <Richard_D_Levine@raytheon.com>)
List pgsql-bugs
Rick Levine wrote:
> ECPG does not handle BYTEA columns properly.  When I encode a unsigned char
> array using PQescapeByteaConn and send it to the server, it is not stored as
> the original bytes, but rather is stored as the escaped string (much
> larger).

Yeah, that's clearly not the right way to do it. You could just use
libpq PGExecParams for those queries. I understand that you'd want to
stick to the ECPG way of doing things, but that's a good work-around.

> We know the coder knows the size of the buffer, but ECPG doesn't, so the
> best solution (to my mind) would be to allow the coder to tell ECPG the
> buffer size directly.  A clean way to do this would be to allow an indicator
> variable containing the size, e.g.
>
> EXEC SQL BEGIN DECLARE SECTION;
> unsigned char bytea_hostvar[1024];
> int hostvar_ind = 1024;
> EXEC SQL END DECLARE SECTION;
>
> EXEC SQL AT :connection INSERT INTO Btable
> (index, bytea_col)
> VALUES
> (:index_var, :bytea_hostvar:hostvar_ind);
>
> I'm just sayin... ;)

Yeah, that seems like a clean way to do it. Any idea how this is done in
other databases with embedded C support, like DB2 / Informix? Or SQL
spec, if it has anything to say about this. It would be good to stay
compatible.

(I've added this to the TODO list)

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

pgsql-bugs by date:

Previous
From: "Prasad, Venkat"
Date:
Subject: Integrity check
Next
From: Magnus Hagander
Date:
Subject: Re: BUG #4869: No proper initialization of OpenSSL-Engine in libpq