X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id C9532B439AA for ; Mon, 7 Jul 2003 09:28:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 88111-09 for ; Mon, 7 Jul 2003 06:27:58 -0300 (ADT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 28EE9B430A6 for ; Mon, 7 Jul 2003 06:27:27 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon Jul 07 11:28:02 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id LAA11153; Mon, 7 Jul 2003 11:27:00 +0200 (METDST) Message-ID: <3F093CE3.BE88DC98@rodos.fzk.de> Date: Mon, 07 Jul 2003 11:27:00 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org, Simeon.Mariasoosai@StartelCorp.com Subject: Re: Need help on bytea usage Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/5 X-Sequence-Number: 4319 Simon, My reply is pretty late, maybe you've already find out on your own. Here is what I can show you ... struct measurestation { int Id ; char Name[NAMELEN] ; char ProviderName[NAMELEN] ; char ProviderTime[15] ; float Longitude ; float Latitude ; int Height ; int nValue ; float Value ; int MeasureHght ; struct measurestation* next ; } ; typedef struct measurestation MeasureValues ; ... char CmdLine[1024]; PGconn *conn; PGresult *res; MeasureValues mval ; char ByteaString[1024]; size_t binarylen; /* insert a C struct as bytea type */ memset ( &mval , 0 , sizeof(MeasureValues) ) ; strcpy ( mval.Name , "stat-name" ) ; strcpy ( mval.ProviderName , "prov-name" ) ; /* keep in mind libpq is not thread-safe, so what I use as buffer 'ByteaString' should be 4 times the sizeof(MeasureValues) to be on the safe side (all non-printables bytes become four byte octets \nnn) */ strcpy ( ByteaString , (const char *) PQescapeBytea((unsigned char *) &mval , sizeof(MeasureValues), &binarylen)); sprintf(CmdLine, "INSERT INTO bytea_tab ( bytea_col ) VALUES ('%s');", ByteaString); res = PQexec(conn, CmdLine); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "INSERT command failed\n"); PQclear(res); exit_nicely(conn); } This works for me. Regards, Christoph