Hi guys!!
I am having problems with the external database I created, I have a structured bank called “speakaut.db”, when I try to insert some registry in this bank the system returns me the error code 8. how can I open the database in writing mode ?
Detail: the first time the app is installed, the database is copied from “system.ResourceDirectory” to “system.DocumentsDirectory” and I can enter the records normally, but when the app is closed and reopened the database. Data is in read-only mode.
How do I solve this problem? Follows the code tread that copies the bank to the sandbox.
local sqlite = require (“sqlite3”)
local path = system.pathForFile(“speakaut.db”, system.DocumentsDirectory)
print (path)
file = io.open( path, “r” )
if( file == nil )then
--Database doesn’t already exist, so copy it from the
--resource directory
pathSource = system.pathForFile( “speakaut.db”, system.ResourceDirectory )
print ("PATH SOURCE >> " … pathSource)
fileSource = io.open( pathSource, “rb” )
contentsSource = fileSource:read( “*a” )
--Write Destination File in Documents Directory
pathDest = system.pathForFile( “speakaut.db”, system.DocumentsDirectory )
fileDest = io.open( pathDest, “wb” )
fileDest:write( contentsSource )
– Done
io.close( fileSource )
io.close( fileDest )
end
db = sqlite3.open( path )