Re: Need help on bytea usage

Поиск
Список
Период
Сортировка
От Christoph Haller
Тема Re: Need help on bytea usage
Дата
Msg-id 3F093CE3.BE88DC98@rodos.fzk.de
обсуждение исходный текст
Ответ на Need help on bytea usage  (Simeon Mariasoosai <Simeon.Mariasoosai@StartelCorp.com>)
Список pgsql-interfaces
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
;floatLatitude ;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




В списке pgsql-interfaces по дате отправления:

Предыдущее
От: "Nestor A. Diaz L."
Дата:
Сообщение: PL/Python char(n) problem
Следующее
От: lerkista@gmx.net
Дата:
Сообщение: Migrating DB