Access local storage

8 posts, 0 answers
  1. Developer
    Developer avatar
    5 posts
    Member since:
    Jul 2013

    Posted 10 Sep 2013 Link to this post

    My problem is simple but I can't find anything related to say if is possible or not.

    I want to access the local storage in a device running my Icenium project. I need to know where (in filesystem) the storage is or how can I access it with a SQLite tool in any other way.

    Thank you.
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 13 Sep 2013 Link to this post

    Hi,

    Have you looked at Cordova's localStorage? Accessing an item from the storage is easy as

    var value = window.localStorage.getItem("your_key");

    The sample-localstorage shows how this works on a device.

    However, if you want to store your app results as a file (and not as a string in a key-value store or a DB), you can use Cordova's local FileSystem API.

    Regards,
    Steve
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. Developer
    Developer avatar
    5 posts
    Member since:
    Jul 2013

    Posted 13 Sep 2013 Link to this post

    Sorry but I'm afrid my question is not accurate. The base I want to access isn't the localStorage itself but the webSQL database(see the attached screenshot). I need to access it on the application running on a smartphone or tablet. In the simulator is easy using the Resources Tab on the Debug Window.

    Sorry by the misunderstand.
  4. domiSchenk
    domiSchenk avatar
    55 posts
    Member since:
    Mar 2013

    Posted 16 Sep 2013 Link to this post

    i'm using the following code snippet to open my db:

    if (window.sqlitePlugin !== undefined) {
                           console.log("Using SQLite Plugin DB");
                        // save to global var
                           dbApp.db = window.sqlitePlugin.openDatabase("databasename");
                       }
                       else {
                           // For debuging in simulator fallback to native SQL Lite
                           console.log("Use built in SQLite");
                           dbApp.db = window.openDatabase("databasename", "1.0", "databasename Demo", 200000);
                       }


    this way it works in both version on ion/iphone and on simulator

    create tables:
    dbApp.db.transaction(function(tx) {
                           console.log("Create Table");
                           tx.executeSql("CREATE TABLE IF NOT EXISTS Person(PersonID INTEGER PRIMARY KEY ASC, Name TEXT IsDeleted INTEGER)", [], dbApp.onSuccess, dbApp.onError);
                       });

    and access it:
    dbApp.db.transaction(function(tx) {
                           tx.executeSql("SELECT * FROM Person ",
                                         [],
                                         function(tx, rs) {
                                             var result = [];
                   
                                             for (var i = 0; i < rs.rows.length; i++) {
                                                 var row = rs.rows.item(i);
                                                 result.push({
                                                     PersonID: row['PersonID'],
                                                     Name: row['Name'],
                                                     IsDeleted : row['IsDeleted']
                                                 });
                                             }
                                             success(result);
                                         })
                       });



    i hope this helps you!
  5. Iain
    Iain avatar
    2 posts
    Member since:
    Nov 2013

    Posted 18 Feb 2014 in reply to domiSchenk Link to this post

    Hi,

    I used your code. Can you confirm it works in the AppBuilder simulator?

    When i run the code the callback function after performing a SELECT statement never gets executed.

    Cheers,
    IK
  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 18 Feb 2014 Link to this post

    Hi IK,

    Please note that Cordova plugins do not work in the Simulator and in the AppBuilder companion app.

    Regards,
    Steve
    Telerik
    Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
  7. Iain
    Iain avatar
    2 posts
    Member since:
    Nov 2013

    Posted 18 Feb 2014 in reply to Steve Link to this post

    Hi Steve,

    Thanks for that info. So if i am using the simulator it seems i can fall back to using WebSQL. Am i able to query and execute statements against WebSQL in the simulator?

    Cheers,
    IK
  8. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 18 Feb 2014 Link to this post

    Hi IK,

    Yes you can use WebSQL/IndexedDB when running the app in Simulator. Both are available for inspections in the debugging tools -> Resources.

    Regards,
    Steve
    Telerik
    Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
Back to Top