SQLite records pre defined


Last Updated:

  1. creatiive

    creatiive Member This Topic's Starter

    Joined:
    Jan 14, 2010
    Messages:
    7
    Likes Received:
    0
    hi,

    I've been reading a bunch of tutorials explaining how to create your SQLite database if it isn't already there, and adding records to it etc. What im looking for is how to have records already in the database when it is installed?

    if anyone could point me in the direction of a tutorial or some resource that explains how to achieve this , it would be much appriciated!!

    thanks
     

    Advertisement
  2. sn00zer

    sn00zer Member

    Joined:
    Dec 30, 2009
    Messages:
    17
    Likes Received:
    0
    The easiest way to do this is when you're creating your database.

    If the database isn't there you need to run your script to create the database and then run a script to do your INSERT statements on the database that you just created adding the records.
     
  3. creatiive

    creatiive Member This Topic's Starter

    Joined:
    Jan 14, 2010
    Messages:
    7
    Likes Received:
    0
    but i only ever want the INSERTs to run once - i dont want to have to have that re-execute every time the app is opened, even if they dont actually do any inserting because they keys are already in there, it would still take processing (and i have a lot of records).#


    is it possible to only run the INSERTs if the database gets created, and not if its already there?
     
  4. sn00zer

    sn00zer Member

    Joined:
    Dec 30, 2009
    Messages:
    17
    Likes Received:
    0
    You don't want to create the database every time the app is opened. The first time you open the app . . it will create the database . . and add the records.

    The next time the app is opened . . the database will be there so it won't have to go through that step again.
     
  5. eclipsed4utoo

    eclipsed4utoo Well-Known Member

    Joined:
    Nov 12, 2009
    Messages:
    435
    Likes Received:
    27
    in your same logic where you determine if you need create the database because it doesn't exist, that is when you would do the insert. therefore, you would only be inserting the records when you have to create the database.
     
  6. SFLeBrun

    SFLeBrun Member

    Joined:
    Feb 11, 2010
    Messages:
    9
    Likes Received:
    0
    Are you using a SQLiteOpenHelper derived class to open/create your database?

    The SQLiteOpenHelper has an abstract method, onCreate(), which is called if the database needs to be created. You can execute your INSERT statements in this method after you create the database. This method is only called the first time an application needs to create a database. Next time the application runs, the database file already exists and SQLiteOpenHelper skips the call to onCreate().
     

Share This Page

Loading...