I’m currently struggling with Sqlite on android, based on the info that I got here I managed to avoid some problems, but the main problem right now is that it creates a new database instead of reading from the one I provide in assets.
var dbpath: String = System.applicationStorageDirectory + "/" + "database.db";
var connection:Connection = Sqlite.open(dbpath);
var results: ResultSet = connection.request("SELECT * FROM high_scores ORDER BY score DESC LIMIT 10");
E/Exception( 3390): Error while executing SELECT * FROM high_scores ORDER BY score DESC LIMIT 10 (Sqlite error in SELECT * FROM high_scores ORDER BY score DESC LIMIT 10 : no such table: high_scores)
The issue on Android is that assets are not extracted – they’re in the APK. If it is fast enough, perhaps you can read your database and write to a new location (like the database.db path you have in your code) if it does not exist.
var targetPath = System.applicationStorageDirectory + "/database.db";
if (!FileSystem.exists (targetPath)) {
var bytes = Assets.getBytes ("assets/data/database.db");
File.saveContent (targetPath, bytes);
}
Try Assets.getBytes ("assets/data/database.db"); (if that’s the right name for the file) instead of including System.applicationStorageDirectory
Assets uses asset ID names, not paths, to look things up, so assets/test.txt might resolve to C:\Path\To\Application\assets\test.txt on Windows, ~/path/to/application/assets/test.txt on Linux at runtime, etc