I'm working on a project that involves writing to a SQLite Database from a cross-platform app built with AngularJS, Monaca, and Onsen UI.
Within my app, there's a view where users input their username and password. I store these details in a Service for later retrieval using getters and setters.
However, when attempting to write the stored values to the SQLite database, I encounter an Error Code 6. As per THIS, Error Code 6 indicates that the database is locked. Why might the database be locked and how can I write data to it despite being locked or unlock it?
In my code, I create the table if it doesn't already exist before attempting to write to it. Could this initialization be what's causing the database blockage? Below is my app.js snippet showcasing the database procedures.
var db;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
db = window.openDatabase("myDB", "1.0", "My DB", 200000);
db.transaction(createDB, errorCB, successCB);
}
function createDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS tb_remember_me (id INTEGER PRIMARY KEY, name)');
}
// User clicks the "login" button to save details to Database
$scope.validateLogin = function () {
// Open DB and write to it
db = window.openDatabase("myDB", "1.0", "My DB", 200000);
db.transaction(goInsert, errorCB, successCB);
};
function goInsert() {
db = window.openDatabase("myDB", "1.0", "My DB", 200000);
db.transaction(insertDB, errorCB, successCB);
}
function insertDB(tx) {
// Retrieve user-entered details from Shared Service
$userID = SharedProperties.getUserID();
$userPIN = SharedProperties.getUserPIN();
tx.executeSql('INSERT INTO tb_remember_me (id, name) VALUES (?,?)', [$userID, $userPIN]); // Error occurs here
}
// Transaction error callback
function errorCB(err) {
alert("Error processing SQL with ERROR CODE: " + err.code);
}
// Transaction success callback
function successCB() {
return true;
}