Skip to content

Commit

Permalink
cordova-sqlite-storage 2.1.4 - 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 15, 2017
2 parents 1bea0b2 + 852cff6 commit 912ec40
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 60 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.4

##### 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 (needed for new BUG 666 workaround solution to pass selfTest in case of builtin android.database implementation)

## cordova-sqlite-storage 2.1.3

##### cordova-sqlite-legacy-core 1.0.5
Expand Down
81 changes: 45 additions & 36 deletions README.md

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
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
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-storage",
"version": "2.1.3",
"version": "2.1.4",
"description": "Native interface to SQLite for PhoneGap/Cordova",
"cordova": {
"id": "cordova-sqlite-storage",
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.3">
version="2.1.4">

<name>Cordova sqlite storage plugin</name>

Expand Down
51 changes: 42 additions & 9 deletions spec/www/spec/db-open-close-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,16 +1485,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 @@ -1509,23 +1539,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(ignored, 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(ignored, error) {
}, function(tx_ignored, error) {
ok(false, error);
});
}, function(error) {
}, function(tx_ignored, error) {
ok(false, error);
});
}, function (error) {
Expand Down Expand Up @@ -1779,6 +1809,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 @@ -1958,7 +1990,8 @@ var mytests = function() {
});
});

});
});
}

});

Expand Down
40 changes: 37 additions & 3 deletions spec/www/spec/sqlite-version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ var mytests = function() {
var isWebSql = (i === 1);
var isImpl2 = (i === 2);

// NOTE: MUST be defined in proper describe function scope, NOT outer scope:
var openDatabase = function(name, ignored1, ignored2, ignored3) {
// NOTE 1: MUST be defined in proper describe function scope, NOT outer scope.
// NOTE 2: Using same database name in this script to avoid creating extra,
// unneeded database files.
var openDatabase = function(name_ignored, ignored1, ignored2, ignored3) {
var name = 'sqlite-version-test.db';
if (isImpl2) {
return window.sqlitePlugin.openDatabase({
// prevent reuse of database from default db implementation:
Expand All @@ -50,7 +53,7 @@ var mytests = function() {

describe(suiteName + 'basic sqlite version test(s)', function() {

it(suiteName + 'Check sqlite version (pattern ONLY for WebKit Web SQL & androidDatabaseImplementation: 2)', function(done) {
it(suiteName + 'Check sqlite version (check pattern ONLY for WebKit Web SQL & androidDatabaseImplementation: 2)', function(done) {
var db = openDatabase("check-sqlite-version.db", "1.0", "Demo", DEFAULT_SIZE);

expect(db).toBeDefined();
Expand Down Expand Up @@ -111,6 +114,37 @@ var mytests = function() {

});

describe(suiteName + 'additional sqlite check(s)', function() {

it(suiteName + 'Check default PRAGMA journal_mode setting (plugin ONLY)', function(done) {
if (isWebSql) pending('SKIP: NOT SUPPORTED for (WebKit) Web SQL');

var db = openDatabase("Check-sqlite-PRAGMA-encoding.db", "1.0", "Demo", DEFAULT_SIZE);

expect(db).toBeDefined();

db.executeSql('PRAGMA journal_mode', [], function(rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
// TBD different for builtin android.database implementation:
if (!isWindows && isAndroid && isImpl2) // TBD ...
expect(rs.rows.item(0).journal_mode).toBe('persist');
else
expect(rs.rows.item(0).journal_mode).toBe('delete');

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
}, function(error) {
// NOT EXPECTED:
expect(false).toBe(true);
expect(error.message).toBe('--');
done();
});
}, MYTIMEOUT);

});

});

}
Expand Down
9 changes: 9 additions & 0 deletions src/android/io/sqlc/SQLiteAndroidDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class SQLiteAndroidDatabase

SQLiteDatabase mydb;

boolean isTransactionActive = false;

/**
* NOTE: Using default constructor, no explicit constructor.
*/
Expand All @@ -75,6 +77,10 @@ void open(File dbfile) throws Exception {
*/
void closeDatabaseNow() {
if (mydb != null) {
if (isTransactionActive) {
mydb.endTransaction();
isTransactionActive = false;
}
mydb.close();
mydb = null;
}
Expand Down Expand Up @@ -227,6 +233,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
needRawQuery = false;
try {
mydb.beginTransaction();
isTransactionActive = true;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -242,6 +249,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
try {
mydb.setTransactionSuccessful();
mydb.endTransaction();
isTransactionActive = false;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -256,6 +264,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
needRawQuery = false;
try {
mydb.endTransaction();
isTransactionActive = false;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand Down
8 changes: 4 additions & 4 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 openStep2, openerrorcb, opensuccesscb;
var openerrorcb, opensuccesscb, step2;
if (this.dbname in this.openDBs) {
console.log('database already open: ' + this.dbname);
nextTick((function(_this) {
Expand Down Expand Up @@ -202,12 +202,12 @@
};
})(this);
this.openDBs[this.dbname] = DB_STATE_INIT;
openStep2 = (function(_this) {
step2 = (function(_this) {
return function() {
return cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [_this.openargs]);
cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [_this.openargs]);
};
})(this);
cordova.exec(openStep2, openStep2, 'SQLitePlugin', 'close', [
cordova.exec(step2, step2, 'SQLitePlugin', 'close', [
{
path: this.dbname
}
Expand Down

0 comments on commit 912ec40

Please sign in to comment.