Skip to content

Commit

Permalink
Fix bug 666 workaround to trigger ROLLBACK in next event tick
Browse files Browse the repository at this point in the history
(needed to support version with pre-populated database on Windows)
  • Loading branch information
Christopher J. Brody committed Oct 27, 2017
1 parent 8016cdd commit 1e0fddf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 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-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)
Expand Down
21 changes: 12 additions & 9 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -942,4 +946,3 @@

#### vim: set filetype=coffee :
#### vim: set expandtab :

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.0",
"version": "1.0.1",
"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.0">
version="1.0.1">

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

Expand Down
12 changes: 8 additions & 4 deletions spec/www/spec/db-open-close-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down Expand Up @@ -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'};
Expand Down
20 changes: 13 additions & 7 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 myfn, openerrorcb, opensuccesscb;
var openerrorcb, opensuccesscb;
if (this.dbname in this.openDBs) {
console.log('database already open: ' + this.dbname);
nextTick((function(_this) {
Expand All @@ -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');
}
Expand All @@ -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));
}
};

Expand Down

0 comments on commit 1e0fddf

Please sign in to comment.