Skip to content

Commit

Permalink
Signal INTERNAL ERROR in case of attempt to reuse db (Android/iOS)
Browse files Browse the repository at this point in the history
Should never happen due to workaround solution to
#666
  • Loading branch information
Christopher J. Brody committed Jan 1, 2018
1 parent ef18755 commit 9cc042f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changes

###### cordova-sqlite-legacy-express-core 1.0.5-pre01
###### cordova-sqlite-legacy-express-core 1.0.5-pre02

TBD
- Signal INTERNAL ERROR in case of attempt to reuse db (Android/iOS) (should never happen due to workaround solution to BUG 666)

###### cordova-sqlite-legacy-express-core 1.0.4

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-sqlite-legacy-express-core",
"version": "1.0.5-pre01",
"version": "1.0.5-pre02",
"description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)",
"cordova": {
"id": "cordova-sqlite-legacy-express-core",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-sqlite-legacy-express-core"
version="1.0.5-pre01">
version="1.0.5-pre02">

<name>Cordova sqlite storage plugin - legacy express core version</name>

Expand Down
9 changes: 2 additions & 7 deletions src/android/io/sqlc/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,11 @@ public void onDestroy() {
// --------------------------------------------------------------------------

private void startDatabase(String dbname, JSONObject options, CallbackContext cbc) {
// TODO: is it an issue that we can orphan an existing thread? What should we do here?
// If we re-use the existing DBRunner it might be in the process of closing...
DBRunner r = dbrmap.get(dbname);

// Brody TODO: It may be better to terminate the existing db thread here & start a new one, instead.
if (r != null) {
// don't orphan the existing thread; just re-open the existing database.
// In the worst case it might be in the process of closing, but even that's less serious
// than orphaning the old DBRunner.
cbc.success();
// NO LONGER EXPECTED due to BUG 666 workaround solution:
cbc.error("INTERNAL ERROR: database already open for db name: " + dbname);
} else {
r = new DBRunner(dbname, options, cbc);
dbrmap.put(dbname, r);
Expand Down
6 changes: 4 additions & 2 deletions src/ios/SQLitePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ -(void)openNow: (CDVInvokedUrlCommand*)command
NSString *dbname = [self getDBPath:dbfilename at:dblocation];

if (dbname == NULL) {
// XXX NOT EXPECTED (INTERNAL ERROR):
NSLog(@"No db name specified for open");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"You must specify database name"];
}
else {
NSValue *dbPointer = [openDBs objectForKey:dbfilename];

if (dbPointer != NULL) {
NSLog(@"Reusing existing database connection for db name %@", dbfilename);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Database opened"];
// NO LONGER EXPECTED due to BUG 666 workaround solution:
NSLog(@"INTERNAL ERROR: database already open for db name: %@ (db file name: %@)", dbname, dbfilename);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"INTERNAL ERROR: database already open"];
} else {
const char *name = [dbname UTF8String];
sqlite3 *db;
Expand Down

0 comments on commit 9cc042f

Please sign in to comment.