KeineAhnung
28th November 2014, 17:48
Hi,
I would like to write a function within my QML project that inserts data into a SQLite table and returns the rowid of the inserted line on success.
This is what i got so far:
function saveData(name, mode, adjust) {
var db = getDatabase();
var res = "";
db.transaction(function(tx) {
var rs = tx.executeSql('INSERT INTO profiles ' +
'VALUES (?,?,?);', [name, mode, adjust]);
if (rs.rowsAffected > 0) {
res = tx.executeSql('SELECT last_insert_rowid();');
} else {
res = "Error";
}
});
console.log(res)
return res;
}
But I do net get an integer back, I get an object. How is this done right and is there a better way to do it than what I tried?
Thanks.
I would like to write a function within my QML project that inserts data into a SQLite table and returns the rowid of the inserted line on success.
This is what i got so far:
function saveData(name, mode, adjust) {
var db = getDatabase();
var res = "";
db.transaction(function(tx) {
var rs = tx.executeSql('INSERT INTO profiles ' +
'VALUES (?,?,?);', [name, mode, adjust]);
if (rs.rowsAffected > 0) {
res = tx.executeSql('SELECT last_insert_rowid();');
} else {
res = "Error";
}
});
console.log(res)
return res;
}
But I do net get an integer back, I get an object. How is this done right and is there a better way to do it than what I tried?
Thanks.