Skip to content

Commit

Permalink
selfTest database cleanup fixes
Browse files Browse the repository at this point in the history
- cleanup (delete) database in separate step
- do not ignore close or delete error on any platforms
- fix logging & return statements
  • Loading branch information
Christopher J. Brody committed Dec 10, 2017
1 parent a61b965 commit 452d3c9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 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.3-pre01
###### cordova-sqlite-legacy-express-core 1.0.3-pre02

TBD
- selfTest database cleanup do not ignore close or delete error on any platforms

###### cordova-sqlite-legacy-express-core 1.0.2

Expand Down
39 changes: 22 additions & 17 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -881,24 +881,20 @@

, (tx2_err) ->
SelfTest.finishWithError errorcb, "readTransaction error: #{tx2_err}"

, () ->
# CLEANUP & FINISH:
db.close () ->
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, (cleanup_err)->
# TBD IGNORE THIS ERROR on Windows (and WP8):
if /Windows /.test(navigator.userAgent) or /IEMobile/.test(navigator.userAgent)
console.log "IGNORE CLEANUP (DELETE) ERROR: #{JSON.stringify cleanup_err} (Windows/WP8)"
successcb()

# CLEANUP & FINISH:
db.close () ->
SelfTest.cleanupAndFinish successcb, errorcb
return

, (close_err) ->
# DO NOT IGNORE CLOSE ERROR ON ANY PLATFORM:
SelfTest.finishWithError errorcb, "close error: #{close_err}"
return
SelfTest.finishWithError errorcb, "Cleanup error: #{cleanup_err}"

, (close_err) ->
# TBD IGNORE THIS ERROR on Windows (and WP8):
if /Windows /.test(navigator.userAgent) or /IEMobile/.test(navigator.userAgent)
console.log "IGNORE close ERROR: #{JSON.stringify close_err} (Windows/WP8)"
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, successcb
return
SelfTest.finishWithError errorcb, "close error: #{close_err}"

, (select_err) ->
SelfTest.finishWithError errorcb, "SELECT error: #{select_err}"
Expand All @@ -910,13 +906,22 @@
SelfTest.finishWithError errorcb, "Open database error: #{open_err}"
return

cleanupAndFinish: (successcb, errorcb) ->
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, (cleanup_err)->
# DO NOT IGNORE CLEANUP DELETE ERROR ON ANY PLATFORM:
SelfTest.finishWithError errorcb, "CLEANUP DELETE ERROR: #{cleanup_err}"
return
return

finishWithError: (errorcb, message) ->
console.log "selfTest ERROR with message: #{message}"
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, ->
errorcb newSQLError message
# FUTURE TODO: return
# FUTURE TODO log err2
, (err2)-> errorcb newSQLError "Cleanup error: #{err2} for error: #{message}"
return
, (err2)->
console.log "selfTest CLEANUP DELETE ERROR #{err2}"
errorcb newSQLError "CLEANUP DELETE ERROR: #{err2} for error: #{message}"
return
return

## Exported API:
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.3-pre01",
"version": "1.0.3-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.3-pre01">
version="1.0.3-pre02">

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

Expand Down
37 changes: 14 additions & 23 deletions www/SQLitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,28 +762,10 @@
}, function(tx2_err) {
return SelfTest.finishWithError(errorcb, "readTransaction error: " + tx2_err);
}, function() {
return db.close(function() {
return SQLiteFactory.deleteDatabase({
name: SelfTest.DBNAME,
location: 'default'
}, successcb, function(cleanup_err) {
if (/Windows /.test(navigator.userAgent) || /IEMobile/.test(navigator.userAgent)) {
console.log("IGNORE CLEANUP (DELETE) ERROR: " + (JSON.stringify(cleanup_err)) + " (Windows/WP8)");
successcb();
return;
}
return SelfTest.finishWithError(errorcb, "Cleanup error: " + cleanup_err);
});
db.close(function() {
SelfTest.cleanupAndFinish(successcb, errorcb);
}, function(close_err) {
if (/Windows /.test(navigator.userAgent) || /IEMobile/.test(navigator.userAgent)) {
console.log("IGNORE close ERROR: " + (JSON.stringify(close_err)) + " (Windows/WP8)");
SQLiteFactory.deleteDatabase({
name: SelfTest.DBNAME,
location: 'default'
}, successcb, successcb);
return;
}
return SelfTest.finishWithError(errorcb, "close error: " + close_err);
SelfTest.finishWithError(errorcb, "close error: " + close_err);
});
});
});
Expand All @@ -797,15 +779,24 @@
return SelfTest.finishWithError(errorcb, "Open database error: " + open_err);
});
},
cleanupAndFinish: function(successcb, errorcb) {
SQLiteFactory.deleteDatabase({
name: SelfTest.DBNAME,
location: 'default'
}, successcb, function(cleanup_err) {
SelfTest.finishWithError(errorcb, "CLEANUP DELETE ERROR: " + cleanup_err);
});
},
finishWithError: function(errorcb, message) {
console.log("selfTest ERROR with message: " + message);
SQLiteFactory.deleteDatabase({
name: SelfTest.DBNAME,
location: 'default'
}, function() {
return errorcb(newSQLError(message));
errorcb(newSQLError(message));
}, function(err2) {
return errorcb(newSQLError("Cleanup error: " + err2 + " for error: " + message));
console.log("selfTest CLEANUP DELETE ERROR " + err2);
errorcb(newSQLError("CLEANUP DELETE ERROR: " + err2 + " for error: " + message));
});
}
};
Expand Down

0 comments on commit 452d3c9

Please sign in to comment.