Reputation: 707
This is the code in question. I've been trying to get working.
The issue, is that the variable result in the callback doesn't have any rows in it.
But this is present only in Safari. Chrome works perfectly.
The Database on Safari and Chrome is showing the correct values in the database.
The result variable has an interesting property in it:
SQLResultSet
insertId: Error: InvalidAccessError: DOM Exception 15
But the rows array is not present.
db.transaction(function (tx) {
tx.executeSql("INSERT INTO QUIZZES (id,name,completed,icon) VALUES (coalesce((SELECT max(id) FROM QUIZZES),0)+1,?,0,?)", [json.name,json.icon],
function (tx, result) {
console.log('Inserted Quiz. Selecting Quiz');
tx.executeSql("SELECT * FROM QUIZZES ", [],
function (tx, result) {
console.log(result);
var quizid = result.rows[0].id;
console.log(quizid);
},
errorCB);
});
},
errorCB);
What I've tried is re-working my code from one transaction to multiple separate calls to DB via the db.transaction(... in the callbacks.
And I also tried rewriting the queries themselves, or writing queries that will return the correct result 100% of the time. Yet, got got nowhere.
Thank you for your help in advance
Upvotes: 1
Views: 1032
Reputation: 707
The issue is that Chrome is much more lenient in how you structure your code.
Selecting the results from a query should be done: via
results.rows.item(0).id;
rather than
result.rows[0].id;
Note the item.
This solved the issue for me.
Upvotes: 6