Skip to content

Commit

Permalink
cordova-sqlite-legacy-core 1.0.5
Browse files Browse the repository at this point in the history
Merge branch 'cordova-sqlite-legacy-express-core' into cordova-sqlite-legacy-core
  • Loading branch information
Christopher J. Brody committed Dec 11, 2017
2 parents d076119 + 4c7b59c commit 45aba72
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
.metadata/*
*.swp
*~
spec/myplugin
spec/plugins
spec/platforms
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changes

##### 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-legacy-core 1.0.4

- New workaround solution to BUG 666: close db before opening (ignore close error)
Expand Down
51 changes: 36 additions & 15 deletions README.md

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -874,24 +874,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 @@ -903,13 +899,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-legacy-core",
"version": "1.0.4",
"version": "1.0.5",
"description": "Native interface to SQLite for PhoneGap/Cordova (legacy core version branch)",
"cordova": {
"id": "cordova-sqlite-legacy-core",
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-legacy-core"
version="1.0.4">
version="1.0.5">

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

Expand Down
2 changes: 1 addition & 1 deletion spec/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.plugins.sqlite.tests" version="0.0.1"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Cordova-sqlite-spec</name>
<name>cordova-sqlite-spec</name>
<description>
Runs the unit tests suite for the Cordova SQLite plugin.
</description>
Expand Down
4 changes: 0 additions & 4 deletions spec/platforms/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions spec/plugins/.gitignore

This file was deleted.

48 changes: 32 additions & 16 deletions spec/www/spec/db-open-close-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,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 @@ -155,19 +154,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 @@ -182,30 +190,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));
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 @@ -229,6 +229,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
2 changes: 2 additions & 0 deletions spec/www/spec/db-tx-value-bindings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,13 @@ var mytests = function() {
// we would like to know, so the test is coded to fail if it starts
// working there.
if(isWebSql) {
/* SKIP IN THIS VERSION BRANCH:
ok(expected.indexOf(name) === -1, 'field value: ' +
JSON.stringify(name) + ' should not be in this until a bug is fixed ' +
JSON.stringify(expected));
equal(name.length, 0, 'length of field === 0');
// */
start();
return;
}
Expand Down
28 changes: 18 additions & 10 deletions src/android/io/sqlc/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@

import android.annotation.SuppressLint;

import android.util.Base64;
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 java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -27,19 +30,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 @@ -760,28 +760,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 @@ -795,15 +777,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 45aba72

Please sign in to comment.