Corona Geek #47 – Working With Data in Corona SDK

Corona Geek #47 – Working With Data in Corona SDK

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

Charles McKeever

Charles McKeever is a life long computer geek who enjoys exploring technologies to understand how they work, how they can be smashed together, and how they can be used to fuel entrepreneurial endeavors.

  • Matt Kauble
    Posted at 08:13h, 26 July

    Thanks for the great data info. I also would love to get a link to the parse tutorials Jen mentioned. Does anyone have that?

  • TDS
    Posted at 21:40h, 29 August

    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 = 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 = pathSource, “rb” )
    contentsSource = fileSource:read( “*a” )
    –Write Destination File in Documents Directory
    pathDest = system.pathForFile( “zip.sqlite”, system.DocumentsDirectory )
    fileDest = pathDest, “wb” )
    fileDest:write( contentsSource )
    — Done
    io.close( fileSource )
    io.close( fileDest )

    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???


    • DrBurton
      Posted at 15:34h, 30 August

      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.

      • TDS
        Posted at 22:08h, 02 September

        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.

Post A Comment