i am wondering abt the example W3C Offline Web Apps the example
function renderNotes() {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Notes(title TEXT, body TEXT)',
[]);
tx.executeSql(‘SELECT * FROM Notes’, [], function(tx, rs) {
for(var i = 0; i < rs.rows.length; i++) {
renderNote(rs.rows[i]);
}
});
});
}
has the create table before the 'main' executeSql()
. will it be better if i do something like
$(function() {
// create table 1st
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Notes(title TEXT, body TEXT)',
[]);
});
// when i execute say to select/modify data, i just do the actual action
db.transaction(function(tx) {
tx.executeSql(‘SELECT * FROM Notes’, [], function(tx, rs) {
...
}
});
db.transaction(function(tx) {
tx.executeSql(‘INSERT ...’, [], function(tx, rs) {
...
}
});
})
i was thinking i don't need to keep repeating the CREATE IF NOT EXISTS
right?
Update
function initDatabase() {
notes = openDatabase("todolist", "1.0", "To-Do List", 1*1024*1024, function (notes) {
notes.changeVersion("", "1.0", function(tx) {
tx.executeSql("CREATE TABLE todolist (id INTEGER, task TEXT)", [], function(tx, rs) {
alert("Table created");
});
});
})
}