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

Native Development

Reply
Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Best way to organise data in lists

Hi,

 

I am looking to do an app that has multiple lists (to be displayed on different pages). I've more or less figured out how to work with ListView etc. but I am still a noob and I just want to know what are the best practices if I want to create multiple lists.

 

Basically I have List A, B, C and I would like each item to have a checklist too. I have decided to use XML as my database. 

 

My questions are:

1. Should I create separate xml database files for the individual lists, or save them all in one big list (and then just call them by the rootIndexPath? And I assume this is possible?). 

 

2. I want to be able to update the list in the future, but I want to save any user input e.g. the checkbox input. What is the best way to do this? Must I create 2 different XML database for this? If so, how do I call on both of them at the same time and how should I join the 2 databases?

 

3. Is XML the best way to do this?

 

My data mostly consist of:

- Category (as sorted into List A, B, C already)

- ID

- Title

- Subtitle

- Status

- Summary

- Icon (for lists)

- (and potentially/ have not decided if I can do this yet), more Images.

 

Thanks in advance!!

Please use plain text.
Developer
BBSJdev
Posts: 6,083
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: Best way to organise data in lists

I mostly use XML for static data, for data that needs to be manipulated and updated I recommend using sql.

 

1) I would switch to using sql now to save a lot of work in the future, with sql you don't need to worry about how many levels of hierarchy you have you just produce a different query for each result you desire.

 

2) You *can* join XML together using several of the datamodels provided but again I recommend switching to sql.

 

3) None of the formats really supports images that well (links to images yes), images can actually be stored in sql using the blob type.

 

Really in terms of dependency, recovery from failure, sql is the only real option for data that changes as the base of your app.

 

 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Best way to organise data in lists

Thanks for your suggestion. Does that mean that in the future, should I want to update my database, what I will do is write a script to insert more rows into the database?
Please use plain text.
Developer
BBSJdev
Posts: 6,083
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: Best way to organise data in lists

In sql what you are referring to are called tables and it's best to try and future proof when you first create them.
If you know you might want to add something in a future version of your app that will require an extra field then put it in now, no harm can be done.

However if you need to add something at a later date sql makes this fairly simple to do without affecting other data.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
BlackBerry Development Advisor
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Best way to organise data in lists

As BBSJdev says, SQL is probably the way to go. We have a few samples that use it like the Quotes sample app: https://github.com/blackberry/Cascades-Samples/tree/master/quotes

 

For images, what I would do is just store any images somewhere in the data folder of your app, and then just store the path as a string in SQL. You can store the actual image if you want, but Imageview and simliar classes work best with the file path, and this way it minmizes the size of the data you are putting in and puling out of SQL.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.
Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Best way to organise data in lists

Thanks! Lucky I've asked before I embarked on converting all my data into XML :smileytongue: 

Please use plain text.
Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Best way to organise data in lists

Hi guys,

I have been doing some research on this matter and I've came across a problem. I have 3 level heirachy of data to display. This is quite easily done if I use even the automatic Xml datalist function.

My problem with that however, is of how I can merge e.g. my userdata and my main content data.

From what I understand, if I use Sql and I have to use a GroupDataModel, which only allows 2 levels. So how can I still use Sql to store my data?

Maybe to put it into perspective, my data is analogous to:

Artist>Album(s)>Songs.
I want them to be displayed in a list like:
MAIN TITLE: ARTIST
SUB TITLEs: ALBUM [more than one] //Also would like to contain more information in this field.
ITEMS: Songs + [checkbox for user]

Also, I assume I can just load any .db file?

Thanks again!
Please use plain text.
BlackBerry Development Advisor
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Best way to organise data in lists

Well, with SQL you could keep all that in separate tables, linked together with foreign keys, and then pull whatever you wanted out with some JOIN operations. It's not super hard, but if you've never done any SQL before it will require a bit of learning. SQL is a very useful tool for a developer to have access to, though, so I'd recommend learning it even if you decide you want to use XML in the end :smileyhappy:

You can load any file that was created with SQLite. ".db" is kind of overloaded, people have used it for all sorts of databases in the past. So either have your app build your database from a script it the first time it's run, or build it with an external program, package it in as an asset, and then copy it over to the data or db folder the first time your app is run (the assets folder is not writeable)
Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.
Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Best way to organise data in lists

Thank you Paul.

 

I have tried practising with SQL just recently, but with visual studio. Hopefully that will help.

Please use plain text.
BlackBerry Development Advisor
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Best way to organise data in lists

The nice thing about SQL is that even though there are a lot of back ends, it's pretty standard (at least, when you are starting out) so the knowledge is pretty transferable.

Make sure you always guard against SQL injection attacks. http://xkcd.com/327/
Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.