X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AA89552802 for ; Fri, 3 Jun 2005 13:18:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07249-03 for ; Fri, 3 Jun 2005 16:18:26 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.197]) by svr1.postgresql.org (Postfix) with ESMTP id E896452906 for ; Fri, 3 Jun 2005 13:18:25 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 68so889675wra for ; Fri, 03 Jun 2005 09:18:25 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=g1CmLzuTJYNdE1KOKIsOtoeJLiCpBTHILHsnYgzWn51NjEIedaTF21i9NN7H9E35JW7nkm72hDpPlgKfxV6kp9wl88e7FatzQHzOziHwJRI9RXNF0fjWfVxEZc6JOam4MQMpneZeU2MOOb3TZu+TiLMv6CGbAZ/DkQRmzVBYFwc= Received: by 10.54.2.42 with SMTP id 42mr1309509wrb; Fri, 03 Jun 2005 09:18:25 -0700 (PDT) Received: by 10.54.53.40 with HTTP; Fri, 3 Jun 2005 09:18:25 -0700 (PDT) Message-ID: Date: Fri, 3 Jun 2005 11:18:25 -0500 From: David Hinkle Reply-To: David Hinkle To: pgsql-interfaces@postgresql.org Subject: libpq, PQExecParams and the inserting of binary data Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200506/6 X-Sequence-Number: 5574 I have been trying to figure this out all morning, and I've gotten no where so far. I am trying to insert binary data into a bytea column with PQExecParams. I couldn't find any documentation on using PQExecParams with binary parameters, do I tried to do it this way: int _ma_logbody(struct MailData *MailData, char *bodyp, size_t bodylen) { const char *paramValues[2]; char *text_body; PGresult *res; size_t newlen; text_body =3D PQescapeBytea(bodyp, bodylen, &newlen); paramValues[0] =3D MailData->MsgId; paramValues[1] =3D text_body; res =3D PQexecParams(conn, "insert into ma_body (msg_id, body) VALUES ($1, $2);", 2, /* params */ NULL, /* let the backend deduce param type */ paramValues, NULL, /* don't need param lengths since text */ NULL, /* default to all text params */ 0); PQfreemem(text_body); if (PQresultStatus(res) !=3D PGRES_COMMAND_OK) { log(LOG_MAIL, "Postresql insert failed: %s", PQerrorMessage(conn)); log(LOG_MAIL, "bodylen: %d, bodyp: %s", bodylen, bodyp); PQclear(res); PQfinish(conn); conn =3D NULL; return(0); } PQclear(res); return(TRUE); } As you can see, I assumed I could use PQexapeBytea to escape the binary data and then just use the returned value as a text parameter.=20 However, I randomly get insert errors with the error message:=20 "invalid input syntax for type Bytea". If anybody could help me find the right way to do this I'd really apreciate it...