22 July 2013
Corona Geek #47 – Working With Data in Corona SDK
This week we hung out with Dr. Brian Burton, Ed Maurina, Matthew Chapman, Jen Looper, Mohammed 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
Matt Kauble
Posted at 08:13h, 26 JulyThanks for the great data info. I also would love to get a link to the parse tutorials Jen mentioned. Does anyone have that?
Charles McKeever
Posted at 08:19h, 26 JulyMatt, you can find Jen’s Parse tutorials here:
Corona SDK Parse Tutorial 1
Corona SDK Parse Tutorial 2
Corona SDK Parse Tutorial 3
Matt Kauble
Posted at 09:08h, 26 JulyThanks! You are a life saver.
Charles McKeever
Posted at 12:09h, 26 JulyThanks Matt. I always wanted to be multi-colored and crunchy on the outside 😉
TDS
Posted at 21:40h, 29 AugustHi,
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
DrBurton
Posted at 15:34h, 30 August@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.
TDS
Posted at 22:08h, 02 SeptemberThank 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