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
Posts: 22
Registered: ‎04-15-2013
My Device: Dev Alpha C
My Carrier: Mobile Vikings

Store data

Anyone who could help me:

What's the easiest/best/... way to store data (Strings) that is regularly added, removed, plus it must be possible to access it at all times, for example in a "list" (with "auto-update").

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Store data

[ Edited ]

you can use QSettings, I posted a sample on how to do this on Github

 

https://github.com/slashkyle/Cascades-Samples/tree/master/RememberThis

 

Just note, if you're store an integer it's being saved as a string so when you want to read it be sure to

parseInt(cpp.getValueFor("someIntVar",""))

 

Developer
Posts: 22
Registered: ‎04-15-2013
My Device: Dev Alpha C
My Carrier: Mobile Vikings

Re: Store data

Ok, thank you, will take a look at it Smiley Happy

Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Store data


slashkyle wrote:

you can use QSettings, I posted a sample on how to do this on Github

 

https://github.com/slashkyle/Cascades-Samples/tree/master/RememberThis

 

Just note, if you're store an integer it's being saved as a string so when you want to read it be sure to

parseInt(cpp.getValueFor("someIntVar",""))

 


Yeah I use QSettings in my app too, but since the format is typically INI file format, access is a bit too sluggish if you need more than just occasional access or updates. I was surprised to find out that BB10 handsets have a full SQLite implementation on board, which I now use in another part of my app that has more stringent needs.

 

CIAO



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Store data

Interesting, do you have any links with more info on getting started with the SQL

Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Store data

Do you mean get started with SQL, or get started with SQLite, or get started with SQLite on BlackBerry 10? 

 

SQL is a big topic if you have never used it, but if you have, then SQLite and in particular SQLite on BB10 is not too difficult.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Store data

Heard of SQL but never used it, I figured a dive in with google would cover most of that though, but hadn't heard anything about SQL on BB10 prior to this I have a few scenarios I think it could be benificial though

Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Store data

Ok, I'll leave you to learn SQL on your own. As for SQL on BB10, start here, and then here. For performance reasons as well as to avoid some strange error messages I strongly suggest you instantiate a single SqlDataAccess in your app, connect to the DB, and leave it connected until you are ready to exit your app. I have seen some online tutorials that suggest disconnecting after every task, then reconnecting again when you have more SQL stuff to do, but SQLite on BB10 generates some annoying (although not usually fatal) error messages when you do this, usually related to it thinking the DB file is still open from a previous connection. Although not mentioned on the SqlDataAccess page, elsewhere on the BlackBerry Native site I've seen it strongly recommend that you use a single SqlDataAccess for all you app's processes and connect to it on startup, then disconnect on shutdown, so that's what I do.

 

The SQLite database file can be created offline with a SQLite database editing tool then copied from your assets directory to your app's data directory on first run, but you don't need to do it this way. Just have your app create an empty file then connect SqlDataAccess to that. Next execute the DDL to create the schema structure and voila, you have a functional database to run your DML against.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 22
Registered: ‎04-15-2013
My Device: Dev Alpha C
My Carrier: Mobile Vikings

Re: Store data

Might try SQL as well (i have some experience with it outside of BB10) Smiley Happy

 

Thanks guys, really appreciate your help!

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Store data

SQL is pretty great, I'd highly recommend any developer know how to use it at least in basic form. We have some sample apps that demonstrate the use of SQLite with lists like Quotes: https://github.com/blackberry/Cascades-Samples/tree/master/quotes

 

Everything greenmr said was correct, but I would add that before you implement any SQL in your app, you should know what an SQL Injection Attack is, how it works, and how to avoid it. Otherwise, you are going to have a bad time. It's not particularilly difficult to avoid, but you should do the research yourself so you really understand it, since it's a pretty common vulnerability.

 

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