Answer the question
In order to leave comments, you need to log in
Is it possible to modify the local WebSQL database (add columns and a table, for example)
Hello.
I have one application, it uses a WebSQL database.
Everything works well, the database is created, the data is written and read.
But I can't add an additional field to the table. For some reason the function doesn't work.
Those. The created base is not updated in any way. If, for example, you remove it from the cache, then a database with new fields will be created, everything is ok. But already without data :-)
Is there a solution?
Thank you.
// создаем базу
MYDB.init.open = function(){
MYDB.init.db = openDatabase("MYDB","1.0"," super-data-base",1024*1024*5);
}
//создаем табличку
MYDB.init.createTable = function(){
var database = MYDB.init.db;
database.transaction(function(tx){
tx.executeSql("CREATE TABLE IF NOT EXISTS mytable (ID INTEGER PRIMARY KEY ASC,item TEXT,description TEXT)", []);
});
}
//
//разный функции чтения и добавления записей, которые работают
//
//а вот это уже не работает
MYDB.init.updateTable = function(){
var database = MYDB.init.db;
database.transaction(function(tx){
tx.executeSql("ALTER TABLE mytable ADD time VARCHAR NOT NULL BEFORE description");
});
}
Answer the question
In order to leave comments, you need to log in
tx.executeSql has callbacks where you can get the result and error text.
For
tx.executeSql("ALTER TABLE mytable ADD time VARCHAR NOT NULL BEFORE description");
could not prepare statement (1 near "BEFORE": syntax error)
tx.executeSql("ALTER TABLE mytable ADD time VARCHAR NOT NULL");
could not prepare statement (1 Cannot add a NOT NULL column with default value NULL)
ALTER TABLE mytable ADD time VARCHAR NOT NULL DEFAULT ''
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question