Home » U++ Library support » U++ SQL » PostgreSQL and binary data
PostgreSQL and binary data [message #20333] |
Thu, 12 March 2009 01:05  |
Kajko
Messages: 14 Registered: December 2008 Location: Ireland, Serbia
|
Promising Member |
|
|
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
b78a07c7fb9b68436af9fd23f4e76cc5
|
|
|
|
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: Sat Apr 26 19:27:54 CEST 2025
Total time taken to generate the page: 0.00582 seconds
|