Corona GeekThis week we hung out with Dr. Brian Burton, Ed MaurinaMatthew Chapman, Jen LooperMohammed Bennouf, and Theo Rushin, Jr to walk through some example code for storing and accessing data using SQLite and Corona SDK. Dr. Burton walked through a code example that checked for a local SQLite database file, connected to the database, and displayed data in a TableView. The panel had a lot of great questions and tips to share. We plan to discuss how to pull data from remote sources and store the data in a local database in a future hangout.

Be sure to pick up Dr. Burton’s book, “Learning Mobile Application & Game Development with Corona“, for more examples of how to work with databases and Corona SDK.

Corona Labs T-Shirt Winner

Congratulations to David Freeman for winning this week’s Corona Labs’ t-shirt. For your chance to win, follow Corona Geek on Twitter and Facebook, and complete the Corona Geek giveaway form.

Thank you for watching, we’ll see you on next week’s Corona Geek hangout!

Remember To Subscribe

  1. Hi,
    Just a question re the ResourceDirectory(RD) transfer bit.

    As Brian says the Documents Directory(DD) is the place you can save data which can be unaffected by updates.

    My question – if you transfer your db from RD to DD via this code;

    [lua]local path = system.pathForFile(“zip.sqlite”, system.DocumentsDirectory )
    file = io.open( path, “r” )
    if( file == nil )then
    — Doesn’t Already Exist, So Copy it In From Resource Directory
    pathSource = system.pathForFile( “zip.sqlite”, system.ResourceDirectory )
    fileSource = io.open( pathSource, “rb” )
    contentsSource = fileSource:read( “*a” )
    –Write Destination File in Documents Directory
    pathDest = system.pathForFile( “zip.sqlite”, system.DocumentsDirectory )
    fileDest = io.open( pathDest, “wb” )
    fileDest:write( contentsSource )
    — Done
    io.close( fileSource )
    io.close( fileDest )
    end
    [/lua]

    Then what happens if you change data in your original db which is included in your next App update.
    Does this code kind of say “oh the file exists in DD so i will forget about the db file in RD – thus not using the updated db???

    thanks
    TDS

    • @TDS,
      The way the code is currently written, yes, it would see that the file exists and not replace it. You could modify the code so that it the database exists it checks for a version number or some other field to make sure that it is current.
      I’m actually working on a project that is using a version field to ensure that the data is up-to-date.

      • Thank you for clarifying that for me. It was the line in the code saying;

        — Does the database exist in the documents directory (allows updating and persistance)

        which was throwing me – i’m not a database pro but the “allows updating..” and then looking at the if statement stumped me – got me looking up the “r”, “w” etc.. terms trying to understand it.

        If i’m right here what you are suggesting is to first open up both the RD file and the DD file and then within perhaps a table in each have a version number, then it’s a case of checking if the RD one is higher if so copy across ( overwrite “w+” ) the DD , if not then using the DD would be fine.
        thanks
        TDS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>