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
PostgreSQL and binary data [message #20333] Thu, 12 March 2009 01:05 Go to next message
Kajko is currently offline  Kajko
Messages: 14
Registered: December 2008
Location: Ireland, Serbia
Promising Member
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


b78a07c7fb9b68436af9fd23f4e76cc5
Re: PostgreSQL and binary data [message #20335 is a reply to message #20333] Thu, 12 March 2009 11:23 Go to previous messageGo to next message
phirox is currently offline  phirox
Messages: 49
Registered: December 2007
Member
You can just use the data field name BLOB or LONGRAW in your schema. These are both of the type 'bytea' in pgsql. And can be filled with a normal String in upp. Since Strings can contain any raw data(including '\000') this shouldn't provide any problem.
Re: PostgreSQL and binary data [message #20346 is a reply to message #20333] Thu, 12 March 2009 20:45 Go to previous messageGo to next 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)));


Re: PostgreSQL and binary data [message #20393 is a reply to message #20333] Mon, 16 March 2009 13:15 Go to previous messageGo to next message
Kajko is currently offline  Kajko
Messages: 14
Registered: December 2008
Location: Ireland, Serbia
Promising Member
Works Smile
thank you all very much.

Sasa


b78a07c7fb9b68436af9fd23f4e76cc5
Re: PostgreSQL and binary data [message #24363 is a reply to message #20346] Tue, 12 January 2010 20:29 Go to previous messageGo to next message
marroyo is currently offline  marroyo
Messages: 8
Registered: August 2009
Location: Argentina
Promising Member
How can I to save and load binary data (png images) with postgresql?

I can save (i think) but I can't load.

Thanks in advance.

Re: PostgreSQL and binary data [message #24403 is a reply to message #24363] Thu, 14 January 2010 17:03 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Situation has improved a bit, you now have this option:

SQL * Insert(IMAGE)(DATA, SqlBinary(imagedata));


For loading, you do not have to do anything. Just fetch it to String.
Previous Topic: SQLite Schema Bugfix
Next Topic: truncated double values from mysql
Goto Forum:
  


Current Time: Fri Mar 29 11:33:14 CET 2024

Total time taken to generate the page: 0.01219 seconds