Saving an object with a byte array in the DB

Questions, tips and tricks and techniques for scripting in Servoy

Saving an object with a byte array in the DB

Postby d.pearce1417196993 » Thu Feb 12, 2015 1:12 am

I am using an object to store workflow parameters.

This was working fine in a text field where the _response_object contained only strings

{"bywhom":"the solicitor/instructing party","oldidappointments":"B15881EE-1C70-4110-8BB0-795BF9BF6092","appchangereason":"The expert has had to cancel the clinic"}

When adding a pdf into the Object though it starts to go horrible wrong. i just get a 'null'

I have tried switching to a blob field and swtiched the blob serialisation on, but then i get a string back!

I then used iT2Be tools to try and convert what appears to be a string in the blob field that gets stored back to bytes, but the pdf I get back on reading the saved object appears to be 1/3 bigger than in the line before it is saved and blank!

This, I guess is simple, but between my reads and writes, serialisations etc something is going wrong!

Is there a correct way to store a mixed object in the DB, which field type, what serialisation and how do i read it back.

Thanks in advance.

David
d.pearce1417196993
 
Posts: 16
Joined: Fri Nov 28, 2014 7:49 pm

Re: Saving an object with a byte array in the DB

Postby jcompagner » Tue Feb 17, 2015 12:13 pm

first a question, how do you know how to read it back in if the object can be a string or a pdf? How do you interpreted the bytes?

I guess if you use a plain media type column (blob in db) then you can just push the bytes of the pdf or the bytes of the string (without using serializers on the column itself)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 7977
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Saving an object with a byte array in the DB

Postby ROCLASI » Tue Feb 17, 2015 1:09 pm

Hi David,

I think you need to encode the binary (the PDF) with base64 in your object, then serialize it to a JSON and store it in a text column.
This way it's all text and can be de-encoded back to binary.

Hope this helps.
Robert Ivens
ROCLASI Software Solutions / JBS Group, Partner
SAN Developer / Servoy Valued Professional / Servoy Certified Developer
Twitter: @roclasi / @servoyforge
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5209
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests