Skip to content

Commit

Permalink
cordova-sqlite-storage 2.1.3 - merge release
Browse files Browse the repository at this point in the history
Merge branch 'cordova-sqlite-legacy-core' into storage-master
  • Loading branch information
Christopher J. Brody committed Dec 11, 2017
2 parents fdd1a4e + 45aba72 commit 1bea0b2
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 84 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changes

## cordova-sqlite-storage 2.1.3

##### cordova-sqlite-legacy-core 1.0.5

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

- Resolve Java 6/7/8 concurrent map compatibility issue reported in litehelpers/Cordova-sqlite-storage#726, THANKS to pointer by @NeoLSN (Jason Yang/楊朝傑) in litehelpers/Cordova-sqlite-storage#727.
- selfTest database cleanup do not ignore close or delete error on any platforms

## cordova-sqlite-storage 2.1.2

##### cordova-sqlite-legacy-core 1.0.4
Expand Down
41 changes: 25 additions & 16 deletions README.md

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@

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

, () ->
if !readTransactionFinished
SelfTest.finishWithError errorcb, 'readTransaction did not finish'
Expand Down Expand Up @@ -950,24 +951,18 @@
if !secondReadTransactionFinished
SelfTest.finishWithError errorcb, 'second readTransaction did not finish'
return

# 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()
return
SelfTest.finishWithError errorcb, "Cleanup error: #{cleanup_err}"
SelfTest.cleanupAndFinish successcb, errorcb
return

, (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
# DO NOT IGNORE CLOSE ERROR ON ANY PLATFORM:
SelfTest.finishWithError errorcb, "close error: #{close_err}"
# FUTURE TODO: return
return

return

, (select_err) ->
SelfTest.finishWithError errorcb, "SELECT error: #{select_err}"
Expand All @@ -979,13 +974,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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-sqlite-storage",
"version": "2.1.2",
"version": "2.1.3",
"description": "Native interface to SQLite for PhoneGap/Cordova",
"cordova": {
"id": "cordova-sqlite-storage",
Expand All @@ -20,6 +20,7 @@
"ecosystem:cordova",
"cordova-android",
"cordova-ios",
"cordova-osx",
"cordova-windows"
],
"author": "various",
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-storage"
version="2.1.2">
version="2.1.3">

<name>Cordova sqlite storage plugin</name>

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

test_it(suiteName + ' test sqlitePlugin.deleteDatabase()', function () {
stop();
it(suiteName + ' test sqlitePlugin.deleteDatabase()', function (done) {
var db = openDatabase("DB-Deletable", "1.0", "Demo", DEFAULT_SIZE);

function createAndInsertStuff() {
Expand All @@ -1142,19 +1141,28 @@ var mytests = function() {
tx.executeSql('INSERT INTO test VALUES (?)', ['foo']);
});
}, function (err) {
ok(false, 'create and insert tx failed with ERROR: ' + JSON.stringify(err));
// NOT EXPECTED:
console.log('create and insert tx failed with ERROR: ' + JSON.stringify(err));
start();
expect(false).toBe(true);
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toBe('--');
done();

}, function () {
// check that we can read it
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM test', [], function (tx, res) {
equal(res.rows.item(0).name, 'foo');
});
}, function (err) {
ok(false, 'SELECT tx failed with ERROR: ' + JSON.stringify(err));
// NOT EXPECTED:
console.log('SELECT tx failed with ERROR: ' + JSON.stringify(err));
start();
expect(false).toBe(true);
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toBe('--');
done();
}, function () {
deleteAndConfirmDeleted();
});
Expand All @@ -1169,32 +1177,38 @@ var mytests = function() {
db.transaction(function (tx) {
tx.executeSql('SELECT name FROM test', []);
}, function (err) {
ok(true, 'got an expected transaction error');
// EXPECTED RESULT:
expect(err).toBeDefined();
expect(err.message).toBeDefined();
testDeleteError();
}, function () {
// SUCCESS CALLBACK NOT EXPECTED:
console.log('UNEXPECTED SUCCESS: expected a transaction error');
ok(false, 'expected a transaction error');
start();
expect(false).toBe(true);
done();
});
}, function (err) {
// NOT EXPECTED - DO NOT IGNORE ON ANY PLATFORM:
console.log("ERROR: " + JSON.stringify(err));
// XXX TBD IGNORE delete error on Windows:
if (isWindows) return start();
ok(false, 'error: ' + err);
start();
expect(false).toBe(true);
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toBe('--');
done();
});
}

function testDeleteError() {
// should throw an error if the db doesn't exist
deleteDatabase("Foo-Doesnt-Exist", function () {
// SUCCESS CALLBACK NOT EXPECTED:
console.log('UNEXPECTED SUCCESS: expected a delete error');
ok(false, 'expected error');
start();
expect(false).toBe(true);
done();
}, function (err) {
ok(!!err, 'got error like we expected');

start();
// EXPECTED RESULT:
expect(err).toBeDefined();
done();
});
}

Expand Down
1 change: 1 addition & 0 deletions spec/www/spec/db-tx-string-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ var mytests = function() {
if (isWP8) pending('BROKEN on WP(8)'); // [BUG #202] UNICODE characters not working with WP(8)
if (!isWebSql && !isWindows && isAndroid) pending('SKIP for Android plugin (cordova-android 6.x BUG: cordova/cordova-discuss#57)');
if (!isWebSql && !isWindows && !isAndroid && !isWP8) pending('SKIP for iOS/macOS plugin (Cordova BUG: CB-9435)');
if (isWebSql && !isWindows && isAndroid) pending('SKIP for Android Web SQL'); // TBD SKIP for Android Web for now

// NOTE: since the above test shows the UNICODE line separator (\u2028)
// is seen by the sqlite implementation OK, it is now concluded that
Expand Down
26 changes: 17 additions & 9 deletions src/android/io/sqlc/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import android.util.Log;

import java.io.File;

import java.lang.IllegalArgumentException;
import java.lang.Number;
import java.util.concurrent.ConcurrentHashMap;

import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.cordova.CallbackContext;
Expand All @@ -24,19 +27,24 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class SQLitePlugin extends CordovaPlugin {

/**
* Multiple database runner map (static).
* NOTE: no public static accessor to db (runner) map since it would not work with db threading.
* FUTURE put DBRunner into a public class that can provide external accessor.
*
* NOTE: no public static accessor to db (runner) map since it is not
* expected to work properly with db threading.
*
* FUTURE TBD put DBRunner into a public class that can provide external accessor.
*
* ADDITIONAL NOTE: Storing as Map<String, DBRunner> to avoid portabiity issue
* between Java 6/7/8 as discussed in:
* https://gist.github.com/AlainODea/1375759b8720a3f9f094
*
* THANKS to @NeoLSN (Jason Yang/楊朝傑) for giving the pointer in:
* https://github.com/litehelpers/Cordova-sqlite-storage/issues/727
*/
static ConcurrentHashMap<String, DBRunner> dbrmap = new ConcurrentHashMap<String, DBRunner>();
static Map<String, DBRunner> dbrmap = new ConcurrentHashMap<String, DBRunner>();

/**
* NOTE: Using default constructor, no explicit constructor.
Expand Down
37 changes: 14 additions & 23 deletions www/SQLitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,28 +837,10 @@
SelfTest.finishWithError(errorcb, 'second readTransaction did not finish');
return;
}
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 @@ -874,15 +856,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 1bea0b2

Please sign in to comment.