facebook

First time startup & Install for App

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #338367 Reply

    nvts
    Member

    Hello,

    I have developed an app that has a SQLite db with a few tables. All is working well in the test center. What I would like to do is only on the initial run of the app have it create the DB, Tables and insert a row in each table before the first screen is loaded.

    The reason is that I use a login screen that is getting the password from the DB and it will give a SQL error if it is not created first. But I only want this to run one time only.

    Also, Chrome has problems with a function that creates the tables & inserts the first row, but the work fine if I open the Dev Tool and insert the statements to create the table and insert the initial row.

    Any suggestions?

    Cheers…

    #338377 Reply

    Hi nvts,

    My first thought was to use localstorage and save a bool value to check if is the first time the app runs, something like:

    if(localStorage.getItem(“firstInit”)==true){
    //SQL code for creation of database and tables
    localStorage.setItem(“firstInit”,false);
    }

    But then, I recalled, that you can check if a database exists before to create it with sql, i.e. create table if not exists TableName. See this stackoverflow thread where you can find a few approaches suggested:
    http://stackoverflow.com/questions/1601151/how-do-i-check-in-sqlite-whether-a-table-exists

    Feel free to use the approach that you preffer.

    #338660 Reply

    nvts
    Member

    I decided to create an initial DB creation function and store to local storage. This worked the best and now I can use it for other items in the future.

    // Check for Initial Run
    if (localStorage.getItem(“nvtsDlInitial”) === null) {
    populateDB();
    localStorage.setItem(“nvtsDlInitial”,false);
    }

    Cheers…

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: First time startup & Install for App

You must be logged in to post in the forum log in