Home » U++ Library support » U++ SQL » PostgreSQL and binary data
Re: PostgreSQL and binary data [message #20346 is a reply to message #20333] |
Thu, 12 March 2009 20:45   |
|
Kajko wrote on Wed, 11 March 2009 20:05 | Hi,
Can anyone tell me/give me example code of how to store/read binary data from PostgreSQL and what type of field is needed.
Data size will vary from 50k to 5MB.
Thanks,
Sasa
|
I use..
String ToBytea(const String& s)
{
size_t rl;
PostgreSQLSession &pses = (PostgreSQLSession &) SQL.GetSession();
unsigned char *sb = PQescapeByteaConn(pses.GetPGConn(), (const byte *) ~s, s.GetLength(), &rl);
String k(sb, rl + 16);
PQfreemem(sb);
return k;
}
to save binary data. Of course field type in database is also bytea.
For example:
SQL & ::Insert(DESCRIPTION_PICTURE)
(DESCRIPTION_ID, id)
(DESCRIPTION, data.desc)
(BIG_PICTURE, ToBytea(encoder.SaveString(data.oryginal)))
(SMALL_PICTURE, ToBytea(encoder.SaveString(data.resized)));
|
|
|
Goto Forum:
Current Time: Mon Apr 28 03:31:52 CEST 2025
Total time taken to generate the page: 0.01304 seconds
|