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

Web and WebWorks Development

Reply
New Contributor
Posts: 2
Registered: ‎06-03-2010
My Device: Curve8900
My Carrier: EDGE

Widget data store issue

We are developing a widget app which needs to store data into device so it can be used next time app is running. There are various data size from < 100 bytes to 400~500kb.

Before start, we made some investigation and find there are four possible ways:

1. Cookie. There are two limitations: a) cookies are lost after device reboots (DT358816) b) data stored in each cookie piece is small (~4k)

2. File IO. By using of Java extension, widget can access the file system and read/write files. There is no protection on the file so crypto methods might be needed. Also when the data size stored in file becomes large, the file operations could be inefficient

3. Google gears. Gears is good in both performance and data protection. The only drawback is on most Blackberry devices, gears database file can only be stored on external memory card. This solution can't work on devices without memory cards

4. Persistent object. Widget can access persistent objects by Java extension. As PO access can be controlled by certificate, it's no security problem. But this solution also has performance issue when data grows large

From the above analysis, it's hard to decide which way we should adopt for the widget app. We might store data with small size into PO while big size in gears. This combined solution is still not perfect concerning the memory card limitation.

What is the suggestion from RIM and for what reason the gears file must be stored on memory card?

Developer
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: Widget data store issue

My personal suggestion is to use the Gears Sqlite database.

 

I have a check in all of my widgets on startup that looks for an inserted SD card. If one is not detected, I alert the user that certain functionality is disabled without an SD card.

 

More than likely, users will have an SD card since BlackBerry's come packaged with them. Of course I am assuming the amount of users who would use their device without an SD card are slim. I keep a lot of documents and music on mine and personally think the phone misses a good chunk of utility without it.

_________________________________________
www.jasonmace.com/blackberry
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget data store issue

Definitely you will want to go with SQLite.  I believe 99% of all BlackBerry smartphones are sold with a micro SD card from the wireless carrier.

 

I would recommend to stay away from Persistent Objects.  This methodology of data storage will be phased out over time and we will be recommending people to move to SQLite.  There's a lot of concentration here at RIM to further invest in SQLite to ensure fantastic performance.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 2
Registered: ‎06-03-2010
My Device: Curve8900
My Carrier: EDGE

Re: Widget data store issue

Hi, jmace and Tim

 

I understand SQLite should be the best choice. Yet I still have two questions regarding the behavior of database:

 

1. In my widget app, there are some user data must always be available for display even the SD card doesn't present. I don't understand why it's designed as the SQLite DB file has to be stored in SD card so could you give me some explanation?

 

2. When I connect the device to PC via USB, I will be prompted with modes to use. If I choose "Mass Storage", the SD card is recognized as a disk in Windows Explorer and my widget app can't access the SQLite file unless I unplug the cable. That means I can't access all data when I enable USB charging

 

It looks like these two questions can be solved if SQLite DB file can be stored into internal memory.

Developer
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: Widget data store issue

I can't speak for the reasons RIM has chosen the Sqlite on the media card route, but I would guess it was due to the minimal amount of internal memory that devices generally have.

 

As for the USB mass storage mode, there is also a check you can do for that. If the device is connected in mass storage mode, I generally prompt the user to unplug their device to continue.

_________________________________________
www.jasonmace.com/blackberry
Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget data store issue

 


punpuny wrote:

Hi, jmace and Tim

 

I understand SQLite should be the best choice. Yet I still have two questions regarding the behavior of database:

 

1. In my widget app, there are some user data must always be available for display even the SD card doesn't present. I don't understand why it's designed as the SQLite DB file has to be stored in SD card so could you give me some explanation?

 

2. When I connect the device to PC via USB, I will be prompted with modes to use. If I choose "Mass Storage", the SD card is recognized as a disk in Windows Explorer and my widget app can't access the SQLite file unless I unplug the cable. That means I can't access all data when I enable USB charging

 

It looks like these two questions can be solved if SQLite DB file can be stored into internal memory.


 

Answer for 1)

The data must be stored on either an SD card or the built in SD card for a Bold 9000 or a Storm device.  If you are using a Bold 9000 or Storm you will not need an SD card.  These cards are needed because SQLite requires a Posix file system in order to read/write data.  The on-board device memory does not run a Posix file system.  

 

Answer for 2)

When you choose Mass Storage mode, Windows basically takes over access to the SD card as a USB key.  Enabling this mode makes it so that SQLite cannot acquire the proper locks on the database files.  Jmace made some good suggestions.  You can check for mass storage mode using "blackberry.system.isMassStorageActive()"

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 2
Registered: ‎08-16-2010
My Device: Not Specified

Re: Widget data store issue

How to set gears will store data on external memory card  ?

 

where is the location directory is used for gears in the memory card (SD Card) ?.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget data store issue

Hi agusbb,

 

The location of the gears database is determined by the following simple algorithm... if a built in eMMC memory card is on the device it will store the data there.  If it is not present it will store it on the inserted SD card.

 

All databases are encrypted.

 

Locations of where the databases are stored can be found in the Gears database documentation:

 

http://www.blackberry.com/developers/docs/widgetapi/google.gears.database.Database.html

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 2
Registered: ‎08-16-2010
My Device: Not Specified

Re: Widget data store issue

[ Edited ]

Can we push to store the gears database in inserted SD Card ?

 

Where is the location of gears database, if we use simulator ?

 

can we change the location directory for gears database ?

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget data store issue

You unable to tell Gears to store the data on the SD card if there is a built in eMMC card in the device.  It will always follow the logic outlined in my previous post.

 

If you simulate the SD card in the device simulator, the files will be located in the directory that you specify to the simulator to be the emulated root of the SD card.

 

If the database is stored on the on-board eMMC card it will be located in the path specified in the previous post.  You can browse the local file system of the simulator using the BlackBerry File browser application on the BlackBerry OS to find this location.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter