Skip to content

Commit

Permalink
cordova-sqlite-legacy-core 1.0.6 - merge release
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 14, 2017
2 parents 7aa81a4 + ec654b6 commit 852cff6
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 40 deletions.
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.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-legacy-core 1.0.5

###### cordova-sqlite-legacy-express-core 1.0.3
Expand Down
63 changes: 37 additions & 26 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-legacy-core",
"version": "1.0.5",
"version": "1.0.6",
"description": "Native interface to SQLite for PhoneGap/Cordova (legacy core version branch)",
"cordova": {
"id": "cordova-sqlite-legacy-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-core"
version="1.0.5">
version="1.0.6">

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

Expand Down
1 change: 1 addition & 0 deletions spec/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<!-- other spec file(s): -->
<script src="spec/self-test.js"></script>
<script src="spec/sqlite-version-test.js"></script>
<script src="spec/db-tx-string-test.js"></script>
<script src="spec/db-tx-sql-results.js"></script>
<script src="spec/sql-batch-test.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions spec/www/spec/db-tx-sql-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ var mytests = function() {

if (isWebSql) {
// Web SQL STANDARD:
// 1. this is a native object that is NOT affected by the change (SKIP for Android 5.x/+):
if (!isAndroid || /Android [1-4]/.test(navigator.userAgent))
// 1. this is a native object that is NOT affected by the change (SKIP for Android 5.x/+ and iOS):
if (isAndroid && /Android [1-4]/.test(navigator.userAgent))
expect(temp1.data).toBe('test');
// 2. object returned by second resultSet.rows.item call not affected:
expect(temp2.data).toBe('test');
Expand Down
157 changes: 157 additions & 0 deletions spec/www/spec/sqlite-version-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/* 'use strict'; */

var MYTIMEOUT = 12000;

var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios

var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1)
var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1)
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);

// The following openDatabase settings are used for Plugin-implementation-2
// on Android:
// - androidDatabaseImplementation: 2
// - androidLockWorkaround: 1
var scenarioList = [
isAndroid ? 'Plugin-implementation-default' : 'Plugin',
'HTML5',
'Plugin-implementation-2'
];

var scenarioCount = (!!window.hasWebKitBrowser) ? (isAndroid ? 3 : 2) : 1;

var mytests = function() {

for (var i=0; i<scenarioCount; ++i) {

describe(scenarioList[i] + ': sqlite version test(s)', function() {
var scenarioName = scenarioList[i];
var suiteName = scenarioName + ': ';
var isWebSql = (i === 1);
var isImpl2 = (i === 2);

// 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:
name: 'i2-'+name,
androidDatabaseImplementation: 2,
androidLockWorkaround: 1,
location: 'default'
});
}
if (isWebSql) {
return window.openDatabase(name, "1.0", "Demo", DEFAULT_SIZE);
} else {
return window.sqlitePlugin.openDatabase({name: name, location: 'default'});
}
}

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

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();

db.transaction(function(tx) {
expect(tx).toBeDefined();

tx.executeSql('SELECT SQLITE_VERSION() AS myResult', [], function(tx_ignored, rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
// Check pattern (both Web SQL & plugin)
expect(rs.rows.item(0).myResult).toMatch(/3\.[0-9]+\.[0-9]+/);
// NOT IN THIS VERSION BRANCH:
// Check specific [plugin only]:
// ...

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

});

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

it(suiteName + 'Check internal database encoding: UTF-16le for Windows, UTF-8 for others (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 encoding', [], function(rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
if (isWindows)
expect(rs.rows.item(0).encoding).toBe('UTF-16le');
else
expect(rs.rows.item(0).encoding).toBe('UTF-8');

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

});

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);

});

});

}

}

if (window.hasBrowser) mytests();
else exports.defineAutoTests = mytests;

/* vim: set expandtab : */
9 changes: 9 additions & 0 deletions src/android/io/sqlc/SQLiteAndroidDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class SQLiteAndroidDatabase

SQLiteDatabase mydb;

boolean isTransactionActive = false;

/**
* NOTE: Using default constructor, no explicit constructor.
*/
Expand All @@ -70,6 +72,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 @@ -195,6 +201,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams,
needRawQuery = false;
try {
mydb.beginTransaction();
isTransactionActive = true;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -210,6 +217,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams,
try {
mydb.setTransactionSuccessful();
mydb.endTransaction();
isTransactionActive = false;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -224,6 +232,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams,
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 852cff6

Please sign in to comment.