[SOLVED] Local storage working on Desktop but not in Android
-
Ok, here goes the code:
I have a global variable:
@var _db = null;@I open the database with:
@function openDB()
{
_db = Sql.LocalStorage.openDatabaseSync("myScores", "1.0", "", 1000000, createTables);
}@And createTables is (I trimmed some of the SQLs to keep the post shorter):
@function createTables(db)
{
db.transaction(
function(tx){
tx.executeSql("CREATE TABLE IF NOT EXISTS songs ...");
tx.executeSql("CREATE TABLE IF NOT EXISTS notes ...");
}
);
}@And then I have several functions to read/write which follow the same pattern:
@function insertNewSong(songName)
{
_db.transaction(
function(tx) {
tx.executeSql("INSERT INTO songs (title) VALUES (?)", [songName]);
var results = tx.executeSql("SELECT MAX(id) AS mid FROM songs");
functionResult = results.rows.item(0).mid;
}
);
}@ -
Hi,
I think you need to set permissions to your database file first on Android.
-
I'm not sure if th following applies when done through the js api's
I had to do this when copying database during first run of app
@
QString dbfilepath = QDir::currentPath()+"/Scores.db";
if(!QFile::exists(dbfilepath))
{
QFile::copy(":/db/db/Scores.db", QDir::currentPath()+"/Scores.db");
QFile::setPermissions(QDir::currentPath()+"/Scores.db",QFile::ReadOwner|QFile::WriteOwner);
}
@ -
Ok, I've got it figured out. It's quite silly, but I'll post it, maybe it will help someone.
The problem is that, for whatever reason, the database version doesn't get saved in the ini file and it remains blank. So when I closed the application and opened it again calling openDatabaseSync with version "1.0" made everything stop, because the version was not the same. Changing the database version in the code to blank solved it.
The desktop version was working because at some point I had manually modified the ini file (and forgot about it).I want to thank everyone who took their time and tried to help me.
-
That's great. It was a good effort from you.
You can mark the thread as solved by editing the thread title and prepend [solved] so that other's may know that this thread has a possible solution.