I have a query related to this.
My current sit - iOS only.
Have database with game data is downloaded with app and game accesses it via
local pathSq = system.pathForFile( “database.db”, system.ResourceDirectory )
ie system.ResourceDirectory - I currently only read only no writing to it - and if in future did require writing would probably create separate file.
In Corona Geek 47 - there was mention of possible problems with access to ResourceDirectory (re Android). And the files associated with this episode had the following code;
[lua]require(“sqlite3”)
local widget = require(“widget”)
local zip = {}
local doneDB = false
– Does the database exist in the documents directory (allows updating and persistance)
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
– One Way or Another The Database File Exists Now
[/lua]
My question relates to the “(allows updating and persistance)” - HOW?
I’m really a newbie - but have gotten some apps up and running - but if i change the database under my current situation it gets included in the binary so when user downloads they get the new version of the database and since the app accesses this db - no problem.
If i implement this transfer of db to the system.DocumentsDirectory - how can any changes to the downloaded db be included??
The way i read it is the code checks to see if the db exists in system.DocumentsDirectory - if it does then the app will use this db rather than the one in system.ResourceDirectory - am i correct?
just me trying to understand here - Can i assume that the check to see if db exists Checks All properties of the db file - ie database.db {filename}, file size, file create date, file modified date { metadata (if thats the correct term) } and all properties would have to match perfectly between system.DocumentsDirectory & system.ResourceDirectory. - If they did not match perfectly then the system.DocumentsDirectory file would be overwritten with the new db file.
Am i right in that assumption?
thanks
TDS