S
S
Serezhka2013-06-06 11:36:40
JavaScript
Serezhka, 2013-06-06 11:36:40

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

1 answer(s)
A
Alexey Zhurbitsky, 2013-06-06
@Serezhka

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");

Mistake:
could not prepare statement (1 near "BEFORE": syntax error)

For
tx.executeSql("ALTER TABLE mytable ADD time VARCHAR NOT NULL");

Mistake:
could not prepare statement (1 Cannot add a NOT NULL column with default value NULL)

Try
ALTER TABLE mytable ADD time VARCHAR NOT NULL DEFAULT ''

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question