Unconditionally decrement transaction depth (#8008)
…otherwise we may end up in a situation where we're always stuck in an "already in a transaction" state and often neglect to actually enter a real transaction!
This commit is contained in:
parent
d7d0733177
commit
de4fe132a7
|
@ -507,20 +507,22 @@ TODO: better-sqlite3 provides its own transaction method which we should be usin
|
||||||
SqlTiddlerDatabase.prototype.transaction = function(fn) {
|
SqlTiddlerDatabase.prototype.transaction = function(fn) {
|
||||||
const alreadyInTransaction = this.transactionDepth > 0;
|
const alreadyInTransaction = this.transactionDepth > 0;
|
||||||
this.transactionDepth++;
|
this.transactionDepth++;
|
||||||
if(alreadyInTransaction) {
|
try {
|
||||||
return fn();
|
if(alreadyInTransaction) {
|
||||||
} else {
|
return fn();
|
||||||
this.runStatement(`BEGIN TRANSACTION`);
|
} else {
|
||||||
try {
|
this.runStatement(`BEGIN TRANSACTION`);
|
||||||
var result = fn();
|
try {
|
||||||
this.runStatement(`COMMIT TRANSACTION`);
|
var result = fn();
|
||||||
} catch(e) {
|
this.runStatement(`COMMIT TRANSACTION`);
|
||||||
this.runStatement(`ROLLBACK TRANSACTION`);
|
} catch(e) {
|
||||||
throw(e);
|
this.runStatement(`ROLLBACK TRANSACTION`);
|
||||||
} finally {
|
throw(e);
|
||||||
this.transactionDepth--;
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
} finally {
|
||||||
|
this.transactionDepth--;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue