Skip to content

Commit

Permalink
cordova-sqlcipher-adapter 0.1.11 - merge release
Browse files Browse the repository at this point in the history
Merge branch 'cordova-sqlite-legacy-core' into cipher-ext-master
  • Loading branch information
Christopher J. Brody committed Dec 29, 2017
2 parents 7c4404e + 852cff6 commit 313592d
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 100 deletions.
16 changes: 16 additions & 0 deletions CHANGES.md
@@ -1,5 +1,21 @@
# Changes

## cordova-sqlcipher-adapter 0.1.11

##### cordova-sqlite-legacy-core 1.0.6

###### cordova-sqlite-legacy-express-core 1.0.4

- Cleaned up workaround solution to BUG 666: close db before opening (ignore close error)
- android.database end transaction if active before closing

##### 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-sqlcipher-adapter 0.1.10

- Windows 8.1 and Windows Phone 8.1 supported again, NOW DEPRECATED
Expand Down
85 changes: 51 additions & 34 deletions README.md

Large diffs are not rendered by default.

39 changes: 28 additions & 11 deletions SQLitePlugin.coffee.md
Expand Up @@ -250,14 +250,16 @@
# store initial DB state:
@openDBs[@dbname] = DB_STATE_INIT

# NEW WORKAROUND SOLUTION to BUG litehelpers/Cordova-sqlite-storage#666:
# Request to native implementation to close existing database
# connection if it is already open. Wait for success or error
# response before opening the database.
openStep2 = =>
# UPDATED WORKAROUND SOLUTION to cordova-sqlite-storage BUG 666:
# Request to native side to close existing database
# connection in case it is already open.
# Wait for callback before opening the database
# (ignore close error).
step2 = =>
cordova.exec opensuccesscb, openerrorcb, "SQLitePlugin", "open", [ @openargs ]
return

cordova.exec openStep2, openStep2, 'SQLitePlugin', 'close', [ { path: @dbname } ]
cordova.exec step2, step2, 'SQLitePlugin', 'close', [ { path: @dbname } ]

return

Expand Down Expand Up @@ -908,6 +910,7 @@

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

, () ->
if !readTransactionFinished
SelfTest.finishWithError errorcb, 'readTransaction did not finish'
Expand Down Expand Up @@ -951,13 +954,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)->
SelfTest.finishWithError errorcb, "Cleanup error: #{cleanup_err}"
SelfTest.cleanupAndFinish successcb, errorcb
return

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

return

, (select_err) ->
SelfTest.finishWithError errorcb, "SELECT error: #{select_err}"
Expand All @@ -969,13 +977,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
@@ -1,6 +1,6 @@
{
"name": "cordova-sqlcipher-adapter",
"version": "0.1.10",
"version": "0.1.11",
"description": "SQLCipher database adapter for PhoneGap/Cordova, based on cordova-sqlite-storage",
"cordova": {
"id": "cordova-sqlcipher-adapter",
Expand All @@ -21,6 +21,7 @@
"ecosystem:cordova",
"cordova-android",
"cordova-ios",
"cordova-osx",
"cordova-windows"
],
"author": "various",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
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-sqlcipher-adapter"
version="0.1.10">
version="0.1.11">

<name>Cordova sqlcipher adapter</name>

Expand Down
2 changes: 1 addition & 1 deletion spec/config.xml
@@ -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
99 changes: 74 additions & 25 deletions spec/www/spec/db-open-close-delete-test.js
Expand Up @@ -1051,8 +1051,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 @@ -1063,19 +1062,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 @@ -1090,30 +1098,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 Expand Up @@ -1339,16 +1355,46 @@ var mytests = function() {
});
}

describe('repeated open/close/delete test(s)', function() {
var scenarioName = isAndroid ? 'Plugin-implementation-default' : 'Plugin';
var suiteName = scenarioName + ': ';
for (var i=0; i<pluginScenarioCount; ++i) {

describe(pluginScenarioList[i] + ': repeated open/close/delete test(s)', function() {
var scenarioName = pluginScenarioList[i];
var suiteName = scenarioName + ': ';
var isImpl2 = (i === 1);

// NOTE: MUST be defined in function scope, NOT outer scope:
var openDatabase = function(first, second, third) {
if (first.constructor === String ) throw new Error('string not expected here');

// androidDatabaseImplementation: 2 (builtin android.database implementation):
if (isImpl2) {
var dbname = first.name;
return window.sqlitePlugin.openDatabase({
name: 'i2-'+dbname,
// database location setting needed here (value ignored on Android):
location: 'default',
androidDatabaseImplementation: 2,
androidLockWorkaround: 1
}, second, third);
}

return window.sqlitePlugin.openDatabase(first, second, third);
}

var deleteDatabase = function(first, second, third) {
if (first.constructor === String ) throw new Error('string not expected here');

// androidDatabaseImplementation: 2 (builtin android.database implementation):
if (isImpl2) {
var dbname = first.name;
return window.sqlitePlugin.deleteDatabase({
name: 'i2-'+dbname,
// database location setting needed here (value ignored on Android):
location: 'default',
androidDatabaseImplementation: 2
}, second, third);
}

window.sqlitePlugin.deleteDatabase(first, second, third);
}

Expand All @@ -1363,23 +1409,23 @@ var mytests = function() {
var db1 = openDatabase(dbargs, function () {
var db2 = openDatabase(dbargs, function () {
db1.readTransaction(function(tx1) {
tx1.executeSql('SELECT 1', [], function(tx1d, results) {
tx1.executeSql('SELECT 1', [], function(tx_ignored, results) {
ok(true, 'db1 transaction working');
start(1);
}, function(error) {
}, function(tx_ignored, error) {
ok(false, error);
});
}, function(error) {
ok(false, error);
});
db2.readTransaction(function(tx2) {
tx2.executeSql('SELECT 1', [], function(tx2d, results) {
tx2.executeSql('SELECT 1', [], function(tx_ignored, results) {
ok(true, 'db2 transaction working');
start(1);
}, function(error) {
}, function(tx_ignored, error) {
ok(false, error);
});
}, function(error) {
}, function(tx_ignored, error) {
ok(false, error);
});
}, function (error) {
Expand Down Expand Up @@ -1633,6 +1679,8 @@ var mytests = function() {
test_it(suiteName + ' repeatedly open and close 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 ???:
if (isAndroid && isImpl2) pending('FAILS on builtin android.database implementation (androidDatabaseImplementation: 2)');

var dbName = 'repeatedly-open-and-close-faster-5x.db';
var dbargs = {name: dbName, location: 'default'};
Expand Down Expand Up @@ -1812,7 +1860,8 @@ var mytests = function() {
});
});

});
});
}

});

Expand Down
1 change: 1 addition & 0 deletions spec/www/spec/db-tx-string-test.js
Expand Up @@ -854,6 +854,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
Expand Up @@ -1316,6 +1316,7 @@ var mytests = function() {
tx.executeSql('SELECT name FROM test', [], function (tx_ignored, rs) {
var name = rs.rows.item(0).name;

// TBD ???:
// There is a bug in WebKit and Chromium where strings are created
// using methods that rely on '\0' for termination instead of
// the specified byte length.
Expand All @@ -1326,6 +1327,7 @@ var mytests = function() {
// we would like to know, so the test is coded to fail if it starts
// working there.

// TBD
// QUICK TEST WORKAROUND
if (isWebSql && isAndroid) return done();

Expand Down

0 comments on commit 313592d

Please sign in to comment.