Skip to content

Commit

Permalink
Fix for failure to call open callback #110
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Oppenheim authored and Chris Brody committed Aug 21, 2014
1 parent 1fc29e1 commit a43fec6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/android/org/pgsqlite/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ private boolean executeAndPossiblyThrow(Action action, JSONArray args, CallbackC
o = args.getJSONObject(0);
dbname = o.getString("name");

DBRunner r = new DBRunner(dbname);
DBRunner r = new DBRunner(dbname, cbc);
this.rmap.put(dbname, r);
this.cordova.getThreadPool().execute(r);
// TODO should send an async callback
break;

case close:
Expand Down Expand Up @@ -194,6 +193,16 @@ public void onDestroy() {
*
* @param dbName The name of the database file
*/
private void openDatabase(String dbname, CallbackContext cbc) {
try {
openDatabase(dbname);
cbc.success();
} catch (SQLiteException e) {
cbc.error("can't open database " + e);
throw e;
}
}

private void openDatabase(String dbname) {
if (this.getDatabase(dbname) != null) {
// TODO should wait for the db thread(s) to stop (!!)
Expand Down Expand Up @@ -716,14 +725,16 @@ private void bindPreHoneycomb(JSONObject row, String key, Cursor cursor, int i)
private class DBRunner implements Runnable {
final String dbname;
final BlockingQueue<DBQuery> q;
final CallbackContext openCbc;

DBRunner(final String dbname) {
DBRunner(final String dbname, CallbackContext cbc) {
this.dbname = dbname;
this.q = new LinkedBlockingQueue<DBQuery>();
this.openCbc = cbc;
}

public void run() {
openDatabase(dbname);
openDatabase(dbname, this.openCbc);

try {
DBQuery dbq = q.take();
Expand Down

0 comments on commit a43fec6

Please # to comment.