From 1e0fddfd1de8bb337176faa0c894b4bc05180c6a Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Fri, 27 Oct 2017 16:20:50 -0400 Subject: [PATCH] Fix bug 666 workaround to trigger ROLLBACK in next event tick (needed to support version with pre-populated database on Windows) --- CHANGES.md | 4 ++++ SQLitePlugin.coffee.md | 21 ++++++++++++--------- package.json | 2 +- plugin.xml | 2 +- spec/www/spec/db-open-close-delete-test.js | 12 ++++++++---- www/SQLitePlugin.js | 20 +++++++++++++------- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4bd1f14a2..6b1c2daf8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changes +###### cordova-sqlite-legacy-express-core 1.0.1 + +- Fix bug 666 workaround to trigger ROLLBACK in the next event tick (needed to support version with pre-populated database on Windows) + ###### cordova-sqlite-legacy-express-core 1.0.0 - Workaround solution to BUG litehelpers/Cordova-sqlite-storage#666 (hanging transaction in case of location reload/change) diff --git a/SQLitePlugin.coffee.md b/SQLitePlugin.coffee.md index 6e1313003..a3dc8c066 100644 --- a/SQLitePlugin.coffee.md +++ b/SQLitePlugin.coffee.md @@ -213,12 +213,14 @@ success @ return + # (done) + else console.log 'OPEN database: ' + @dbname opensuccesscb = => # NOTE: the db state is NOT stored (in @openDBs) if the db was closed or deleted. - # console.log 'OPEN database: ' + @dbname + ' succeeded' + console.log 'OPEN database: ' + @dbname + ' ok' #if !@openDBs[@dbname] then call open error cb, and abort pending tx if any if !@openDBs[@dbname] @@ -248,19 +250,21 @@ # store initial DB state: @openDBs[@dbname] = DB_STATE_INIT - # As a WORKAROUND SOLUTION to BUG litehelpers/Cordova-sqlite-storage#666: + # 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. - if not txLocks[@dbname] - myfn = (tx) -> - tx.addStatement 'ROLLBACK' - return - @addTransaction new SQLitePluginTransaction @, myfn, null, null, false, false + nextTick => + if not txLocks[@dbname] + myfn = (tx) -> + tx.addStatement 'ROLLBACK' + return + @addTransaction new SQLitePluginTransaction @, myfn, null, null, false, false - cordova.exec opensuccesscb, openerrorcb, "SQLitePlugin", "open", [ @openargs ] + cordova.exec opensuccesscb, openerrorcb, "SQLitePlugin", "open", [ @openargs ] return @@ -942,4 +946,3 @@ #### vim: set filetype=coffee : #### vim: set expandtab : - diff --git a/package.json b/package.json index e2077ab48..65ee03f73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-sqlite-legacy-express-core", - "version": "1.0.0", + "version": "1.0.1", "description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)", "cordova": { "id": "cordova-sqlite-legacy-express-core", diff --git a/plugin.xml b/plugin.xml index 7cb41b37c..c67c46975 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.1"> Cordova sqlite storage plugin - legacy express core version diff --git a/spec/www/spec/db-open-close-delete-test.js b/spec/www/spec/db-open-close-delete-test.js index 33957b6fd..31d710f8c 100755 --- a/spec/www/spec/db-open-close-delete-test.js +++ b/spec/www/spec/db-open-close-delete-test.js @@ -577,8 +577,10 @@ 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 due to current background processing implementation: - if (!isAndroid && !isWindows && !isWP8) pending('POSSIBLY BROKEN on iOS/macOS (background processing implementation)'); + // 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'); var dbName = "Immediate-close-delete-Reopen.db"; var dbargs = {name: dbName, location: 'default'}; @@ -846,8 +848,10 @@ var mytests = function() { // Needed to support some large-scale applications: test_it(suiteName + ' repeatedly open and delete database faster (5x)', function () { - // TBD CURRENTLY BROKEN on iOS/macOS due to current background processing implementation: - if (!isAndroid && !isWindows && !isWP8) pending('CURRENTLY BROKEN on iOS/macOS (background processing implementation)'); + // 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'); var dbName = 'repeatedly-open-and-delete-faster-5x.db'; var dbargs = {name: dbName, location: 'default'}; diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 476349c80..6d612d448 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -162,7 +162,7 @@ }; SQLitePlugin.prototype.open = function(success, error) { - var myfn, openerrorcb, opensuccesscb; + var openerrorcb, opensuccesscb; if (this.dbname in this.openDBs) { console.log('database already open: ' + this.dbname); nextTick((function(_this) { @@ -175,6 +175,7 @@ opensuccesscb = (function(_this) { return function() { var txLock; + console.log('OPEN database: ' + _this.dbname + ' ok'); if (!_this.openDBs[_this.dbname]) { console.log('database was closed during open operation'); } @@ -201,13 +202,18 @@ }; })(this); this.openDBs[this.dbname] = DB_STATE_INIT; - if (!txLocks[this.dbname]) { - myfn = function(tx) { - tx.addStatement('ROLLBACK'); + nextTick((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.addTransaction(new SQLitePluginTransaction(this, myfn, null, null, false, false)); - } - cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [this.openargs]); + })(this)); } };