The Mobile Experiment V – Storing data with SQLite API

Finally I managed to publish this new post. I’ve been busy this holidays, with very little time to write something useful.

If you look at the previous posts, you’ll see that our application are already able to allow user input. It comes the moment where the task you’re working on is done, and you press the Stop button:

At that time, besides the fact that the GUI has to be ready to start another project, the previous data has to be stored somewhere. You probably remember that we are using the PersistentStore to save our live data, so it is always possible to restore the previous state even after a reboot.

Now, when the project is done, the complete data must be stored somewhere else. Depending on this system is used, you could have dozens of projects records after a week, or month. It also must be easy to retrieve them to send by email (check here our application feature requirements).

Although a straight text file would do the job, I’ve decided using the built-in SQLite support that was added to the Blackberry OS since version 5.0. My decision was driven by the fact that this would be the best way to deal with data, even if the application functionality is expanded (present the saved data on screen, edit or deleted saved data, etc…).

You can find few samples and tutorials over the internet about SQLite and Blackberry. I’ve been using RIM’s SQLite Developer Guide to get almost all information I need. This sample code also gave me some interesting information.

The only caveat about this choice is that, to be compatible with all devices, I have to store the database in the SDCard only. Interestingly, the Bold and Storm series support using the internal memory for storage, but not the Torch. Therefore, you have to check what device your app is running to find the right place, or just use the SD card always, like I did.

If you are using the simulator to test your app, you’ll have to create a directory in any place on your computer disk, and tell the simulator to use that directory as SD card. To do so, open the simulator’s menu Simulate -> Change SD Card, click the Add Directory button, and select the desire place.

Another great advantage of using the simulated SD card, is that you can access the SQLite database using any desktop tool, allowing you to add data, create and modify tables, or even test SQL statements without having to run your application over and over.

Although I said “create and modify tables”, I’d suggest that you add the database schema creating in your application. It makes easy to create the database and tables when the application is run the first time.

After a deep research (aka googling for 10-secs), I found the excellent SQLite Expert, which has a free Personal edition that covered all my needs for basic SQL syntax testing, etc… There are other options as well, so you have plenty of choices.

In the next few days I’ll be posting the final article about SQLite with code samples. You can receive real-time updates following me on Twitter: mobicreator.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: