SQLite and Android in 5.1

Hi, I’ve been trying for a while now to use an SQL database on Android (with 5.1) to cache downloaded data. Everything about my DB setup works perfectly on Win64, all creation, opening, writing, reading, queries, work perfectly. But when I swap to an Android build I just seem to hit obstacles at every turn.
Just today I finally navigated past the actual creation of the database by using GInternalFilePath (to bypass any permissions wrangling) instead of ProjectSavedDir(). Finally,

Database->Open(*(SessionPath / DatabaseFileName), ESQLiteDatabaseOpenMode::ReadWriteCreate)

actually executes successfully. However the next step I call

Database->PerformQuickIntegrityCheck()

and it falls right over again deep inside sqlite3 with an SQLITE_IOERR error.
From what I can tell this means that the database is read only, but…but…but… I’ve just created it using ReadWriteCreate. What? NNnggghhhh.

So long story short, I’m at a loss as to how to do this properly on Android, has anyone got any pointers as I don’t know where to look next.

(Min SDK : 26, Target SDK : 28)

TIA.

What I’ve found so far is that everything IS being done properly, but on device if you try to create the db file, the file is initially size 0 and so it fails on Seek in various places inside FSQLiteFileFuncs.

It’s using FPakPlatformFile::Seek(), which returns false if seek pos > file size, and not FFileHandleAndroid::Seek() or FFileHandleWindows::Seek() which returns true no matter what.

If you have a file to work with already, you’re golden and seek/validation works OK. Creating one on device, from scratch = boom.

Still buggy in UE5.4, I have wrote a patch fixing it
https://github.com/EpicGames/UnrealEngine/pull/12118
Hope Epic could merge it soon.

–Patch merged on main branch, problem should be gone in next release as UE5.5

1 Like