Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
simon_hain
Posts: 16,044
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to write and read a blob object in SQLITE

if you can use persistence it may be a lot easier to use.

if you want to use sql i would serialize directly to sql. serializing to json, then storing that in sql makes little sense.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to write and read a blob object in SQLITE

"serializing to json, then storing that in sql makes little sense".

 

There are three advantages I see:

 

1) Deserialization is mostly handled by the JSON parser - you don't have to read the bytes directly

 

2) The data is 'readable' - in that you can extract the blob, stick the string in a JSON parser, and have a good idea of what the data is.  Make debugging easier. 

 

3) My experience serializing Objects is that over time, Objects change.  The advantage of serializing to a form like JSON, is that then the Application program is isolated from this change.  It is easy to deserialize back to a JSONObject and then extract from that JSON Object the information that you need.  This is much simpler than creating a byte stream directly where you need to know the order of the primitives you are extracting and then do some fancy processing where you have contained Objects. 

 

I recognize there are issues with doing this, most notably the extra overhead.  But I think this is worth it and in places I will do this to Objects I store in Persistent store so that the application doesn't have to worry about changes to the persisted Object. 

Please use plain text.
Developer
simon_hain
Posts: 16,044
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to write and read a blob object in SQLITE

serializing to byte stream is not advisable anyhow unless you have to, for example for the OTA-Sync-API.
In sql you can create a database field for every attribute you have and serialize the whole object.

basically the thread asks how to do something very specifically, and while that is possible it would be much easier to do it another way, specifically using persistence or by writing all attributes into sql instead of a blob.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to write and read a blob object in SQLITE

"it would be much easier to do it another way, specifically using persistence or by writing all attributes into sql instead of a blob."

 

Very good point, I have been blinkered by the question and focused on creating a blob rather than storing an Object.  My bad.  Thanks Simon.

 

OP, please review Simon's comments carefully. 

Please use plain text.
Developer
rakesh86shankar
Posts: 998
Registered: ‎05-22-2009
My Device: Not Specified

Re: How to write and read a blob object in SQLITE

Hi Peter,

 

CreateBlobOutputStream is not supported on 6.o API

 

d.createBlobOutputStream( "MyTable1", "MessageBody", d.lastInsertedRowID( ) );

 

is not supported.

 

Is there any max limit of the storage in persistant storage?

 

While saving 400 or 500 Kb Object in device Memory as a persistant Object,if device such as 9650 has flash memory less than 1 GB,Will there any issue in saving DB .

 

 

I am not fully aware of flashmemory .Is there any thing to do while saving as persistant Object.

 

Thanks

Rakesh

 

 

Thanks

Rakesh

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to write and read a blob object in SQLITE

"saving 400 or 500 Kb Object in device Memory"

 

If you only have one of these, then I don't think there would be too much concern.  Would you be concerned about downloading another program that was 1 MB? 

 

"Is there any thing to do while saving as persistant Object."

 

Try this tutorial:

http://supportforums.blackberry.com/t5/Java-Development/Storing-Persistent-Data/ta-p/442785

Please use plain text.
Developer
rakesh86shankar
Posts: 998
Registered: ‎05-22-2009
My Device: Not Specified

Re: How to write and read a blob object in SQLITE

Hi Peter,

 

I will be savingnearly 20 - 25  Objects of max size around 500 - 700 Kb .

 

 " Would you be concerned about downloading another program that was 1 MB?"--->I did nt understand.

 

I will be saving as Object if connectivity is down temporarily and upload it back to server,if connectivity is up.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to write and read a blob object in SQLITE

The flash memory is used for applications, so putting a large object in persistent store reduces the available space the same as loading a similar sized program.  If you were just keeping on 0.5MB sized object, then that would be the same as installing a new 0.5MB application.  That is why I said:

Would you be concerned about downloading another program that was 1 MB?

 

But 25 Objects of that size is potentially significant.  And the time taken to download and upload that size is significant as well.  I would put it on the SD Card, in some form, either convert to SQL row for each image as Simon suggests, or serialize to a byte form and put on SD Card as a file. 

 

Please use plain text.