HTML5 Database Transactions
Posted
by jiewmeng
on Stack Overflow
See other posts from Stack Overflow
or by jiewmeng
Published on 2010-06-03T13:15:42Z
Indexed on
2010/06/03
13:24 UTC
Read the original article
Hit count: 302
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?
© Stack Overflow or respective owner