Skip to content

Commit

Permalink
New bug 666 workaround: close db before opening (ignore close error)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Nov 13, 2017
1 parent 65fc769 commit c2959bb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

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

- New workaround solution to BUG 666: close db before opening (ignore close error)

##### cordova-sqlite-legacy-core 1.0.3

- Suppress warnings when building sqlite3.c & PSPDFThreadSafeMutableDictionary.m on iOS/macOS
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ minimum API level is supported back to SDK 10 (a.k.a. Gingerbread, Android 2.3.3

## Announcements

- New workaround solution to [BUG 666 (litehelpers/Cordova-sqlite-storage#666)](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666) (possible transaction issue after window.location change with possible data loss): attempt to close database before opening (ignore close error)
- Windows 10 (UWP) build with /SAFESEH flag on Win32 (x86) target to specify "Image has Safe Exception Handlers" as described in <https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers>
- Fixed iOS/macOS platform version to use [PSPDFThreadSafeMutableDictionary.m](https://gist.github.com/steipete/5928916) to avoid threading issue ref: [litehelpers/Cordova-sqlite-storage#716](https://github.com/litehelpers/Cordova-sqlite-storage/issues/716)
- Resolved transaction problem after window.location (page) change with possible data loss ref: [litehelpers/Cordova-sqlite-storage#666](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666)
- [brodybits / cordova-sqlite-test-app](https://github.com/brodybits/cordova-sqlite-test-app) project is a CC0 (public domain) starting point (NOTE that this plugin must be added) and may also be used to reproduce issues with this plugin.
- The Lawnchair adapter is now moved to [litehelpers / cordova-sqlite-lawnchair-adapter](https://github.com/litehelpers/cordova-sqlite-lawnchair-adapter).
- [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) now supports SELECT BLOB data in Base64 format on all platforms in addition to REGEXP (Android/iOS/macOS) and pre-populated database (all platforms).
Expand Down
21 changes: 7 additions & 14 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,15 @@
# store initial DB state:
@openDBs[@dbname] = DB_STATE_INIT

# As a WORKAROUND SOLUTION to BUG litehelpers/Cordova-sqlite-storage#666
# (in the next event tick):
# If the database was never opened on the JavaScript side
# start an extra ROLLBACK statement to abort any pending transaction
# (does not matter whether it succeeds or fails here).
# FUTURE TBD a better solution would be to send a special signal or parameter
# if the database was never opened on the JavaScript side.
nextTick =>
if not txLocks[@dbname]
myfn = (tx) ->
tx.addStatement 'ROLLBACK'
return
@addTransaction new SQLitePluginTransaction @, myfn, null, null, false, false

# NEW WORKAROUND SOLUTION to BUG litehelpers/Cordova-sqlite-storage#666:
# Request to native implementation to close existing database
# connection if it is already open. Wait for success or error
# response before opening the database.
openStep2 = =>
cordova.exec opensuccesscb, openerrorcb, "SQLitePlugin", "open", [ @openargs ]

cordova.exec openStep2, openStep2, 'SQLitePlugin', 'close', [ { path: @dbname } ]

return

SQLitePlugin::close = (success, error) ->
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-core",
"version": "1.0.3",
"version": "1.0.4",
"description": "Native interface to SQLite for PhoneGap/Cordova (legacy core version branch)",
"cordova": {
"id": "cordova-sqlite-legacy-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-core"
version="1.0.3">
version="1.0.4">

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

Expand Down
11 changes: 4 additions & 7 deletions spec/www/spec/db-open-close-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ var mytests = function() {

test_it(suiteName + ' database.close (immediately after open) calls its success callback', function () {
// TBD POSSIBLY BROKEN on iOS/macOS due to current background processing implementation:
if (!isAndroid && !isWindows && !isWP8) pending('POSSIBLY BROKEN on iOS/macOS (background processing implementation)');
if (!isAndroid && !isWindows && !isWP8) pending('CURRENTLY BROKEN on iOS/macOS (background processing implementation)');

// asynch test coming up
stop(1);
Expand Down Expand Up @@ -577,10 +577,7 @@ var mytests = function() {
// XXX SEE BELOW: repeat scenario but wait for open callback before close/delete/reopen
// Needed to support some large-scale applications:
test_it(suiteName + ' immediate close, then delete then re-open allows subsequent queries to run', function () {
// TBD POSSIBLY BROKEN on iOS/macOS ...
// if (!isAndroid && !isWindows && !isWP8) pending(...);
// TBD CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK
pending('CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK');
if (!isAndroid && !isWindows && !isWP8) pending('CURRENTLY BROKEN on iOS/macOS (background processing implementation)');

var dbName = "Immediate-close-delete-Reopen.db";
var dbargs = {name: dbName, location: 'default'};
Expand Down Expand Up @@ -850,8 +847,8 @@ var mytests = function() {
test_it(suiteName + ' repeatedly open and delete database faster (5x)', function () {
// TBD POSSIBLY BROKEN on iOS/macOS ...
// if (!isAndroid && !isWindows && !isWP8) pending(...);
// TBD CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK
pending('CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK');
// TBD CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND SOLUTION
pending('CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND SOLUTION');

var dbName = 'repeatedly-open-and-delete-faster-5x.db';
var dbargs = {name: dbName, location: 'default'};
Expand Down
18 changes: 8 additions & 10 deletions www/SQLitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
};

SQLitePlugin.prototype.open = function(success, error) {
var openerrorcb, opensuccesscb;
var openStep2, openerrorcb, opensuccesscb;
if (this.dbname in this.openDBs) {
console.log('database already open: ' + this.dbname);
nextTick((function(_this) {
Expand Down Expand Up @@ -202,18 +202,16 @@
};
})(this);
this.openDBs[this.dbname] = DB_STATE_INIT;
nextTick((function(_this) {
openStep2 = (function(_this) {
return function() {
var myfn;
if (!txLocks[_this.dbname]) {
myfn = function(tx) {
tx.addStatement('ROLLBACK');
};
_this.addTransaction(new SQLitePluginTransaction(_this, myfn, null, null, false, false));
}
return cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [_this.openargs]);
};
})(this));
})(this);
cordova.exec(openStep2, openStep2, 'SQLitePlugin', 'close', [
{
path: this.dbname
}
]);
}
};

Expand Down

0 comments on commit c2959bb

Please sign in to comment.