Skip to content

Commit

Permalink
Possible workaroud for problem reported in #193
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Brody committed Mar 1, 2015
1 parent 31dca30 commit c33608e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/android/org/pgsqlite/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private SQLiteDatabase openDatabase(String dbname, boolean createFromAssets, Cal
try {
if (this.getDatabase(dbname) != null) {
// this should not happen - should be blocked at the execute("open") level
cbc.error("database already open");
if (cbc != null) cbc.error("database already open");
throw new Exception("database already open");
}

Expand All @@ -240,11 +240,11 @@ private SQLiteDatabase openDatabase(String dbname, boolean createFromAssets, Cal

SQLiteDatabase mydb = SQLiteDatabase.openOrCreateDatabase(dbfile, null);

cbc.success();
if (cbc != null) cbc.success();

return mydb;
} catch (SQLiteException e) {
cbc.error("can't open database " + e);
if (cbc != null) cbc.error("can't open database " + e);
throw e;
}
}
Expand Down Expand Up @@ -848,6 +848,14 @@ public void run() {
while (!dbq.stop) {
executeSqlBatch(dbname, dbq.queries, dbq.jsonparams, dbq.queryIDs, dbq.cbc);

// workaround:
if (dbq.queries.length == 1 && dbq.queries[0] == "COMMIT") {
Log.e(SQLitePlugin.class.getSimpleName(), "close and reopen db");
closeDatabaseNow(dbname);
this.mydb = openDatabase(dbname, false, null);
Log.e(SQLitePlugin.class.getSimpleName(), "close and reopen db finished");
}

dbq = q.take();
}
} catch (Exception e) {
Expand Down

0 comments on commit c33608e

Please sign in to comment.