5

I have simple WebSQL database with 1 table and 3 columns. I would like to add one more column, but I can't do it if the database already exist. It's only possible after I have cleaned it in the cache, but then I'm loosing all the data.

How can I add new column to a table without removing the database?

// database creating
MYDB.init.open = function(){
       MYDB.init.db = openDatabase("MYDB","1.0"," super-data-base",1024*1024*5);
}


//table creating    
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)", []);
           });
    }

//
//a lot of code for adding datas and reading datas
//

//database updating that does not work
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");
       });
}

All other UPDATE functions are working well.

Andreas
  • 6,447
  • 2
  • 34
  • 46
sergey_c
  • 741
  • 9
  • 14
  • have you found a solution to this i am working on the exact same thing – Prakash Chennupati Dec 05 '13 at 18:58
  • Yes, this is a correct Request ||| ALTER TABLE mytable ADD time VARCHAR NOT NULL DEFAULT '' ||| (just don't use BEFORE, AFTER, because sqlite-based bases does not support this syntax) Let me know about a result! – sergey_c Dec 12 '13 at 08:17

1 Answers1

6

The correct Request is:

ALTER TABLE mytable ADD time VARCHAR NOT NULL DEFAULT '' 

(without BEFORE, AFTER, because WebSQL does't support this syntax)

sergey_c
  • 741
  • 9
  • 14