1

Can somebody please explain me the error message my ionic / cordova app is returning when writing to an already open SQLite DB?

Reading from it works fine, but writing to is not working...

[Log] {"db":{"openargs":{"name":"mydb.db","dblocation":"docs"},"dbname":"mydb.db"},"txlock":true,"readOnly":false,"executes":[],"finalized":true} (console-via-logger.js, line 174)

This is what SQLite outputs before I run the write transaction:

[Log] OPEN database: mydb.db (console-via-logger.js, line 174)
[Log] new transaction is waiting for open operation (console-via-logger.js, line 174)
[Log] DB opened: mydb.db (console-via-logger.js, line 174)

That's how I write to it

myDB.transaction(function(transaction) {
             var query = "UPDATE Data SET Values='"+dataJSON+"'";
//           console.log(query);
             transaction.executeSql(query,[],
             //On Success
             function(tx, result) {
//               console.log('UPDATE SUCCESSFULLY');
                 deferred.resolve(true);
             },
             //On Error
             function(error){
//               console.log('Backing up data to DB failed');
                 deferred.reject(error);
             });
    });
6
  • I have same issue. It seems that the it trying to do transactions before the database is totally open.. Commented Mar 25, 2016 at 11:52
  • In my case the program already processed a successful read on the DB. Any idea what the error means? Commented Mar 25, 2016 at 22:15
  • This read is over the same table you're trying to write? Commented Mar 26, 2016 at 14:28
  • Yes, reading it first, doing stuff and then update Commented Mar 26, 2016 at 22:08
  • @ElDude: how did u fix that? Commented Dec 12, 2016 at 5:28

1 Answer 1

1

Try to code like this.

function(name,email,phoneno){
var deferred = $q.defer();
posts = undefined;
var query = "UPDATE Data SET Name=?, Email=?, Phone=?";
$cordovaSQLite.execute(dbconn, query, [name,email,phoneno])
.then(function(result) {
posts = result;
deferred.resolve(posts);
}, function (error) {
posts = error;
deferred.reject(posts);
});
posts = deferred.promise;
return $q.when(posts);    
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.