Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ public void open() throws Exception {
_db = null;
throw new Exception(msg);
}
// ALWAYS set _isOpen before the upgrade. deleteSQL() needs it for a DELETE ... WHERE statement.
_isOpen = true;
if (_version > curVersion && _vUpgObject != null && _vUpgObject.size() > 0) {
// if (_vUpgObject != null && _vUpgObject.size() > 0) {
try {
Expand All @@ -328,7 +330,6 @@ public void open() throws Exception {
throw new Exception(msg);
}
}
_isOpen = true;
return;
} else {
_isOpen = false;
Expand Down Expand Up @@ -357,6 +358,9 @@ public void open() throws Exception {
public void close() throws Exception {
if (_db.isOpen()) {
try {
// An open transaction keeps its connection, so _db.close() alone leaves the file locked.
// Only a transaction of the calling thread is ended.
rollbackTransaction();
_db.close();
_isOpen = false;
return;
Expand Down Expand Up @@ -405,10 +409,14 @@ public JSObject execute(String[] statements, Boolean... others) throws Exception
Boolean transaction = others.length == 1 ? others[0] : true;
JSObject retObj = new JSObject();
Integer changes = Integer.valueOf(-1);
boolean ownsTransaction = false;
try {
if (_db != null && _db.isOpen()) {
Integer initChanges = _uSqlite.dbChanges(_db);
if (transaction) beginTransaction();
if (transaction) {
beginTransaction();
ownsTransaction = true;
}
for (String cmd : statements) {
if (!cmd.endsWith(";")) cmd += ";";
String nCmd = cmd;
Expand All @@ -431,7 +439,7 @@ public JSObject execute(String[] statements, Boolean... others) throws Exception
} catch (Exception e) {
throw new Exception(e.getMessage());
} finally {
if (_db != null && transaction && _db.inTransaction()) rollbackTransaction();
if (ownsTransaction && _db.inTransaction()) rollbackTransaction();
}
}

Expand All @@ -447,10 +455,14 @@ public JSObject executeSet(JSArray set, Boolean transaction, String returnMode)
Long lastId = (long) -1;
Integer changes = -1;
JSObject response = new JSObject();
boolean ownsTransaction = false;
try {
if (_db != null && _db.isOpen()) {
int initChanges = _uSqlite.dbChanges(_db);
if (transaction) beginTransaction();
if (transaction) {
beginTransaction();
ownsTransaction = true;
}
for (int i = 0; i < set.length(); i++) {
JSONObject row = set.getJSONObject(i);
JSObject respSet = new JSObject();
Expand Down Expand Up @@ -483,7 +495,7 @@ public JSObject executeSet(JSArray set, Boolean transaction, String returnMode)
} catch (Exception e) {
throw new Exception(e.getMessage());
} finally {
if (_db != null && transaction && _db.inTransaction()) rollbackTransaction();
if (ownsTransaction && _db.inTransaction()) rollbackTransaction();
}
}

Expand Down Expand Up @@ -616,10 +628,14 @@ public JSObject runSQL(String statement, ArrayList<Object> values, Boolean trans
JSObject retObj = new JSObject();
long lastId = (long) -1;
int changes = -1;
boolean ownsTransaction = false;
try {
if (_db != null && _db.isOpen() && statement.length() > 0) {
int initChanges = _uSqlite.dbChanges(_db);
if (transaction) beginTransaction();
if (transaction) {
beginTransaction();
ownsTransaction = true;
}
JSObject response = prepareSQL(statement, values, false, returnMode);
lastId = response.getLong("lastId");
if (lastId != -1 && transaction) commitTransaction();
Expand All @@ -634,7 +650,7 @@ public JSObject runSQL(String statement, ArrayList<Object> values, Boolean trans
} catch (Exception e) {
throw new Exception(e.getMessage());
} finally {
if (_db != null && transaction && _db.inTransaction()) rollbackTransaction();
if (ownsTransaction && _db.inTransaction()) rollbackTransaction();
}
}

Expand Down
Loading