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 Developer
Blackbow
Posts: 7
Registered: ‎02-14-2013
My Device: Curve 9320 / 64GB PlayBook
My Carrier: O2 - UK

LocalStorage or Sqlite? A little help, please...

I am a BlackBerry development newbie, but have some HTML5/CSS/Javascript experience.

 

I am in the process of designing and building a "virtual tabletop" PlayBook app. One major feature I plan to incorporate into my application is the ability to create locally-stored, editable Character Records. It's pretty obvious that I'll need to store the data locally somehow, but I can't work out the best method to use.

 

I am aware that there are a number of different data storage / retrieval methods - I just can't work out the advantages of any one over another. Can anyone point me in the right direction, please?

 

As an aside, I currently have NO access to a Windows PC (or a Mac, for that matter!). I'm hard-coding the pages in a Text Editor on my BlackBerry Curve, uploading the pages to the Web and viewing the results on my PlayBook's Browser - things like plugins for Eclipse or WebWorks are a no-go, I'm afraid...

 

Thanks in advance for your help,

 

Blackbow

Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: LocalStorage or Sqlite? A little help, please...

Localstorage is easiest to use, you would have your characters in JSON objects and just stringify them before storing in the variables. However, I'm guessing that with the type of application you are doing, it would lend itself very well to tabular data - all the characters have the same attributes and you may want to run SQL operations on multiple characters at a time. You will likely find limitations of the localstorage approach fairly soon as you progress in your development.

 

Since you don't have a PC, you might actually benefit from this odd bit of trivia. You can actually use WebInspector in the PlayBook Browser to debug your webpage in the same Browser. Just turn on WebInspector, open a new tab and go the the Wifi IP of your PlayBook, with the port 1337. It's small, but it may help to be able to run the odd console command or look at your SQL tables.

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
mikefromcanada
Posts: 71
Registered: ‎02-06-2013
My Device: 9900
My Carrier: Rogers

Re: LocalStorage or Sqlite? A little help, please...

One issue you may run into with a DB is the lag time involved in DB operations. You have to account for this in your code.

Still, SQlite is quite powerful and IMO that outweighs the potential negatives.
Please use plain text.
New Contributor
fmontanez
Posts: 7
Registered: ‎02-27-2013
My Device: developer
My Carrier: ATT

Re: LocalStorage or Sqlite? A little help, please...

I would go with SQLite for persistent storage for a long term solution. Local storage is definitely easier to use, as it sticks to the key/value pair. 

Please use plain text.
New Developer
Blackbow
Posts: 7
Registered: ‎02-14-2013
My Device: Curve 9320 / 64GB PlayBook
My Carrier: O2 - UK

Re: LocalStorage or Sqlite? A little help, please...

[ Edited ]

@twindsor: Thanks for your help :smileyhappy:

 

I agree with you, the tabular option seems to be the best to go for...

 

Am I right in assuming that each character is represented by a row, and that each column in a table represents an attribute? And that I can have more than one table (characters, monsters, items, etc.)?

 

Thanks also for the tip about the WebInspector - I've added it to my bookmarks!!

 

Blackbow : )

Please use plain text.
New Contributor
fmontanez
Posts: 7
Registered: ‎02-27-2013
My Device: developer
My Carrier: ATT

Re: LocalStorage or Sqlite? A little help, please...

Yes, you can have multiple tables. The row is the data that you put in.

 

ex: 

I have a table for members. The columns would be something like first_name, last_name, address, etc...

 

I insert a record into the members table, John Smith where i'm putting John as first_name and Smith as last_name.

 

When i do a query on the table, it would look something like this

 

db.transaction(function(tx){

     tx.executeSql('SELECT * FROM MEMBERS', [ ], function(tx,results){

          for (var i=0; i < results.rows.length; i++) {

                var row = results.rows.item(i);

                var firstName = row.first_name;

                var lastName = row.last_name;

          }

     });

});

Please use plain text.
New Developer
Blackbow
Posts: 7
Registered: ‎02-14-2013
My Device: Curve 9320 / 64GB PlayBook
My Carrier: O2 - UK

Re: LocalStorage or Sqlite? A little help, please...

Thanks for the help....

 

Am I right in thinking that in your code example, the query would return a list of first and last names for ALL entries in the database?

 

If so, how would I query ONE result (column) from ONE line? For example, how could I find the Email_Address in the Row representing John Doe?

 

Thanks for your patience - it's a lot to get my head around!! :smileyfrustrated:

Please use plain text.
Developer
interfaSys
Posts: 817
Registered: ‎11-19-2009
My Device: Z10, Q10, 9900, 9790, PlayBook,
My Carrier: T-Mobile UK, Three, O2, Orange, Sunrise, Swisscom

Re: LocalStorage or Sqlite? A little help, please...

"One issue you may run into with a DB is the lag time involved in DB operations"

 

@mikefromcanada - Is this the case on BB10 or did you experience this lag on BBOS (Java) ?

 

--
Olivier - interfaSys ltd
Developing for BlackBerry 10 devices using the Sencha Touch framework.
Please use plain text.