Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Kajko wrote on Wed, 11 March 2009 20:05

Hi,

Can anyone tell me/give me example code Smile 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)));


 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SQLite Schema Bugfix
Next Topic: truncated double values from mysql
Goto Forum:
  


Current Time: Wed May 15 11:04:24 CEST 2024

Total time taken to generate the page: 0.02249 seconds