I have an android app (created with cordova) that is already live and in use. There are some data being stored on the device database. I have to make an update that requires an additional column to one of the tables in the database. I want to add the new column without the need to clear the app storage so i created a function that attempts to add a new column before executing some other function dependant on that table. here is the code for that altering code
var alterEntryTable = function()
{
qObj = $q.defer();
dbService.db.transaction(function(tx) {
tx.executeSql(
'ALTER TABLE entry ADD created_at TIMESTAMP ',
[],
function (tx, rss) {
qObj.resolve({error: false});
}, function (tx, rss) {
qObj.resolve({ error: true});
}
);
});
return qObj.promise;
};
the problem is that it always returns an error. someone help please. Thank you
The second parameter in your error handler is a SQLError object. You can log its message property to get details on the error.
function (tx, rss) {
console.log(rss.message);
qObj.resolve({ error: true});
}
Did the error message help at all? I think you're missing COLUMN
in your SQL. It should be ALTER TABLE entry ADD COLUMN created_at TIMESTAMP
.
Also timestamp
is not a datatype in SQLite , but it's harmless to keep it there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.