When I tried to insert an employee record using an HTML form, the data was supposed to be saved in the browser's database (webSQL). However, upon submitting the second record, I encountered an error stating "unable to open database, version mismatch, '1.0' does not match the currentVersion of ''". Can someone provide suggestions on how to resolve this issue?
Below is the code snippet that corresponds to this functionality:
function myFunction() {
debugger;
var obj = {};
obj.first_name = $("#txtFirstName").val();
obj.last_name = $("#txtLastName").val();
obj.qualification = $("#txtQualication").val();
obj.age = $("#txtAge").val();
if (typeof (Storage) !== "undefined") {
// WebSQL supported
var localStorage = openDatabase('dbemp', '1.0', 'employees database', 2 * 1024 * 1024, function () {
console.log("created/found database");
});
var success = function () {
$("#txtFirstName").val("");
$("#txtLastName").val("");
$("#txtQualication").val("");
$("#txtAge").val("");
};
var failure = function () {
alert('Records could not be saved');
};
localStorage.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS employee (first_name, last_name, qualification, age)', function () {
console.log("created table");
}, function () {
tx.executeSql('INSERT INTO employee (first_name, last_name, qualification, age) VALUES (?, ?, ?, ?)',
[obj.first_name, obj.last_name, obj.qualification, obj.age],success,failure);
console.log("Successfully inserted record..");
alert('Record saved locally');
});
});
} else {
console.log("NOT SUPPORTED");
}
}