AppBuilder Large Sqlite Database

6 posts, 0 answers
  1. Adam
    Adam avatar
    70 posts
    Member since:
    Jun 2008

    Posted 01 Jun 2015 Link to this post

    Hey all,

    Just wanted to see if anyone had any ideas or experience with what I'm doing here. We are creating an app that will be packed with an offline large local Sqlite database. Large as in possibly multiple gigs. My current test db is 114 megs. On the companion app, the Sqlite plugin works great and is connecting to my db and pulling the data great. However, since the Sqlite plugin does not work in the simulator, the code is falling back to the PhoneGap api and that api does not seem to be working correctly for me. It may be size restrictions, may be how I'm opening, but I think it's probably creating a new db instead of opening the local db. I've searched around but cannot find any resources that match closely enough with my scenario to know whether I am doing something incorrect for an existing db vs. a new db or local storage.

     

    openDb: function () {
          if (window.sqlitePlugin !== undefined) {
            alert('Sqlite');
            db = window.sqlitePlugin.openDatabase({ name: "cdrom.db", location: 2 });
          } else {
            alert('WebKit');
            // For debugging in simulator fallback to native SQL Lite
            db = window.openDatabase("cdrom.db", "1.0", "Cordova Demo", 120000000);
          }
        }

     

    I would also be interested in knowing if, for the companion app, there is a good way of signaling to the app that some files don't need to be re-downloaded/updated. As you can imagine, it is not quick to download a hundred meg database across most any network. I could try directly connecting the device and updating that way but if there are any tricks here, I'd welcome hearing them.

     

    Thanks!

    Adam.g

  2. Martin Yankov
    Admin
    Martin Yankov avatar
    177 posts

    Posted 04 Jun 2015 Link to this post

    Hi Adam,

    The window.openDatabase() function should open an existing database if it exists and if not - create a new one. The problem is that when you close the simulator the instance is destroyed and nothing is persisted. That is why every time a new database is created. If you want to simulate a restart of the app on a real device, you should use the Reload feature of the simulator. It basically starts the app again without closing the simulator, so all the things in the local storage will be still there.

    Regarding your second question, there is currently no way of doing that. You can suggest this as an idea in the Telerik Platform Feedback Portal. The only way I can see this happening would be to manually upload a file on the device somewhere and then initialize the database from this file on startup of the app. This file will not be deleted when re-deploying the app.

    Keep in mind that these problems will not be present in a production environment since there to update the app you have to increment the version number and the database will be persisted through app updates.

    I hope this information helps.

    Regards,
    Martin Yankov
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  3. Adam
    Adam avatar
    70 posts
    Member since:
    Jun 2008

    Posted 04 Jun 2015 in reply to Martin Yankov Link to this post

    Thanks for the reply, Martin. I think you may just be using some different language so I want to make sure I follow. Right now, it appears that the openDatabase function for the WebKit api is not opening my existing database at all. Are you implying that something in the app cycle is actually destroying my existing database? If not, it shouldn't ever be creating a new database, right? Additionally, you mention local storage, but are you meaning my locally stored database or the actual local storage that is available to apps?

     Your reply for the second question is what I figured and you are correct that I wouldn't be worried about an actual production release of the app.

     Thanks!

    Adam.g

  4. Martin Yankov
    Admin
    Martin Yankov avatar
    177 posts

    Posted 05 Jun 2015 Link to this post

    Hello Adam,

    Just to clarify that from your first post I get that you don't have a problem with the companion app, but with the AppBuilder simulator that is ran on your PC. If this is correct, then my explanation still stands. The problem is not in the app cycle. Closing and opening the simulator does not equal starting and stopping the app. It is the equivalent of starting the app on a new device. In this case, your database is created every time since it's a new device. If you want to simulate restart of an app, use the "Reload" button of the simulator.

    I'm sorry for the misunderstanding. I meant the local data of the simulator. The simulator itself is not an emulator of a device. It is simply a web view that simulates the web view on a device.

    Let me know if I didn't understand you correctly.

    Regards,
    Martin Yankov
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
  5. Adam
    Adam avatar
    70 posts
    Member since:
    Jun 2008

    Posted 05 Jun 2015 in reply to Martin Yankov Link to this post

    Hey Martin,

     My problem with running in the simulator right now is that the WebKit api is creating a database at all. I am packaging an existing database that I want to open and read from, never to create a new database. Is it probable that I have my connection information wrong when calling openDatabase, or perhaps it's in the wrong location, or again, maybe too large for the built-in api by default?

    Thanks!

    Adam.g

  6. Martin Yankov
    Admin
    Martin Yankov avatar
    177 posts

    Posted 08 Jun 2015 Link to this post

    Hello Adam,

    You mentioned you are packaging an existing database in your app? I didn't get that from the other posts. Can you explain how you are doing this? The Cordova SQLite plugin supports this feature with the createFromLocation property. The WebSQL implementation does not support this out of the box. However, there is this thread on StackOverflow that suggest using the openDatabase() function without the version would do the trick for WebSQL. it's worth the try. Otherwise, the openDatabase() function opens an existing database only if it has been created by this same function - it does not work with pre-populated databases.

    Let me know if you have further questions.

    Regards,
    Martin Yankov
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top