Where to keep db-files?

I work on an sqlite3-based application designed only for myself. The problem is how not to rewrite a db-file after reinstallations of an apk-file? (I do not want to use an on-line database which would solve my problem.)

I already use this bit, so that the db-file on the computer would not get to the phone.
build.settings

	excludeFiles =
	{
		-- Exclude unnecessary files for each platform
		all = { "Icon.png", "Icon-*dpi.png", "Images.xcassets", "*.db"},
		android = { "LaunchScreen.storyboardc", },
	},

But if I install the app again, the db-file which was on the previous version is removed completely.

Another way is to store db-file somewhere before installation of a new copy of the app, and then move the file back to the app’s directory where it was stored. But my device is not rooted, so I got no access to any of those folders:

system.ApplicationSupportDirectory
system.CachesDirectory
system.DocumentsDirectory
system.TemporaryDirectory

Can LFS access Android’s “Internal shared storage” folder?

I use Amazon S3 to save files to ensure that everyone’s files can be synchronized.

This should also be the way most games use.

In addition, as far as I know, the objects placed in system.DocumentsDirectory will not change when the APK is updated.

1 Like

I see…
Since it is impossible to move a db-file from folder to folder, but possible to keep it after reinstallations, then I had to create a db-file programmatically. If I ever will need to move the data from that file to another device/file (which I do not plan in the nearest future), I will export data somewhere and import it again; no big deal. Thank you for the hint.

Hello Andrey,

If you mean using “lfs” to access the default sandbox system folders. You can. See Solar2D “lfs” docs here.

local lfs = require( "lfs" )
-- Get raw path to the app documents directory
local doc_path = system.pathForFile( "", system.DocumentsDirectory )
for file in lfs.dir( doc_path ) do
    -- "file" is the current file or directory name
    print( "Found file: " .. file )
end

However, if you mean by external storage outside these sandbox system folders. By default, Solar2D cannot access files outside these sandbox system folders. For Android devices, you could, via plugins. Here are two possible plugins.

(1) Scott’s external storage plugin
https://solar2dmarketplace.com/plugins?ExternalStorage_tech-scotth

(2) StarCrunch’s asset reader plugin
https://github.com/ggcrunchy/corona-plugin-docs/blob/master/AssetReader_sample/main.lua

PS> I have so far only used #2 above.

1 Like