Question

I have no problem creating 1 table, but how do I create 2 in a websql database when a page opens?

//create the table
        curatio.webdb.createTable = function() {
            var db = curatio.webdb.db;
            var db2 = curatio.webdb.db;
            db.transaction(function(tx) {
                           tx.executeSql("CREATE TABLE IF NOT EXISTS loginAE (ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on DATETIME, reminder TEXT, name TEXT, email TEXT, bloodgroup TEXT, dob TEXT, icoe TEXT, work TEXT, mobile TEXT, address TEXT, allergies TEXT, relevant TEXT, medications TEXT)", []);

            db2.transaction(function(tx) {
                           tx.executeSql("CREATE TABLE IF NOT EXISTS personalC(ID INTEGER PRIMARY KEY ASC, name TEXT, added_on DATETIME, note TEXT, dob TEXT, gender TEXT, emergencyContact TEXT, emergencyContactNumber TEXT, ppsn TEXT, mcn TEXT, mce TEXT, hic TEXT, hin TEXT, hie TEXT, allergies TEXT, relevant TEXT, medications TEXT, mobile, TEXT)", []);
                           });
        }
Was it helpful?

Solution

your code is not telling what is happening in curatio.webdb.db but if you want to create 2 tables in same DB it should use something like this:

var dbVersion = "1.0" 
dbHandle = openDatabase('yourDB', dbVersion, 'Test db', 5 * 1024 * 1024);
dbHandle.transaction(function (tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS TBL1 (ID text unique primary key, DESC text)')});
dbHandle.transaction(function (tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS TBL2 (KEY text unique primary key, DATA text)')});

i.e. you open the database once and re-use same handle for each transaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top