Nested transactions
Closed this issue · 3 comments
Are nested transactions supported?
Something like this:
db.transaction( function(tx) {
tx.executeSql('DROP TABLE DEMO');
tx.executeSql( 'CREATE TABLE IF NOT EXISTS DEMO (id INTEGER PRIMARY KEY, data TEXT)', [],
function(tx,results) { console.log('populate1');
tx.executeSql( 'INSERT INTO DEMO (id, data) VALUES (?, ?)',[1,'First row'], function(tx,results) {
console.log('populate2');
tx.executeSql( 'INSERT INTO DEMO (id, data) VALUES (?, ?)', [2,'Second row'],
function(tx,results)
...
...
I tried it and the INSERTs are not working. Debugged the code and after the CREATE TABLE transaction nothing is sent to executeSqlBatch.
I'm not really sure if nested transactions are handled or tested. Does this work in websql?
A couple of things.
- Websql doesn't support nested transactions (i.e. calling db.transaction from within a db.transaction callback).
- The code sample isn't actually using "nested transactions"
- I suspect the problem is that @davidebaltieri31 calls "CREATE TABLE" before the "DROP" table has finished executing. Try restructuring your code like so:
tx.executeSql("DROP TABLE IF EXISTS DEMO ", [], function() {
tx.executeSql("CREATE TABLE IF NOT EXISTS DEMO ...", [], function() {
...
});
});
I agree, you need to remember javascript is async so you will need to nest the calls to know for sure that the previous call is executed.
I'm going to close this issue