Skip to content

Commit

Permalink
Merge branch 'cordova-sqlite-ext-core-common' into cordova-sqlite-ext…
Browse files Browse the repository at this point in the history
…-common-core
  • Loading branch information
Christopher J. Brody committed Jan 31, 2019
2 parents 8360745 + f400ae7 commit 1794f4e
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.swp
*~
node_modules
package-lock.json
spec/myplugin
spec/plugins
spec/platforms
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

##### cordova-sqlite-ext-common-core 0.1.0-dev

###### cordova-sqlite-ext-core-common 0.1.0

- beforePluginInstall.js updates
- use standard Promise
- get the plugin package name from package.json
- use const instead of var (this should be considered a POSSIBLY BREAKING CHANGE since const may not work on some really old Node.js versions)
- remove hasbang line that is not needed

###### cordova-sqlite-storage-ext-core-common 2.0.0

- SQLITE_DBCONFIG_DEFENSIVE flag - iOS/macOS/Windows (POTENTIALLY BREAKING CHANGE)
- remove internal qid usage from JavaScript (not needed)
- non-static Android database runner map (POTENTIALLY BREAKING CHANGE)
- Completely remove old Android SuppressLint (android.annotation.SuppressLint) - POSSIBLY BREAKING CHANGE
- drop workaround for pre-Honeycomb Android API (BREAKING CHANGE)
- no extra @synchronized block per batch (iOS/macOS) - should be considered a POSSIBLY BREAKING change
- remove backgroundExecuteSql method not needed (iOS/macOS)
- Completely remove iOS/macOS MRC (Manual Reference Counting) support - should be considered a POSSIBLY BREAKING change

### cordova-sqlite-storage 2.6.0

- Use cordova-sqlite-storage-dependencies 1.2.1 with SQLite 3.26.0, with a security update and support for window functions
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ New release in December 2018 will include the following major enhancements ([lit

## About this plugin version

This is the common plugin version which supports the most widely used features and serves as the basis for the other versions.
This is a common plugin version branch which supports the most widely used features and serves as the basis for other plugin versions.

This version branch uses a `before_plugin_install` hook to install sqlite3 library dependencies from `cordova-sqlite-storage-dependencies` via npm.

Expand Down Expand Up @@ -222,6 +222,9 @@ See the [Sample section](#sample) for a sample with a more detailed explanation
- `SQLITE_DEFAULT_PAGE_SIZE=1024` and `SQLITE_DEFAULT_CACHE_SIZE=2000` to avoid "potentially disruptive change(s)" from SQLite 3.12.0 described at: <http://sqlite.org/pgszchng2016.html>
- `SQLITE_OS_WINRT` (Windows only)
- `NDEBUG` on Windows (Release build only)
- `SQLITE_DBCONFIG_DEFENSIVE` flag is used for extra SQL safety on iOS/macOS/Windows (TBD NOT USED on Android in this plugin version branch) ref:
- <https://www.sqlite.org/c3ref/c_dbconfig_defensive.html>
- <https://www.sqlite.org/releaselog/3_26_0.html>
- The iOS database location is now mandatory, as documented below.
- This version branch supports the use of two (2) possible Android sqlite database implementations:
- default: lightweight [Android-sqlite-connector](https://github.com/liteglue/Android-sqlite-connector), using SQLite3 NDK component built from [brodybits / Android-sqlite-ext-native-driver (sqlite-storage-native-driver branch)](https://github.com/brodybits/Android-sqlite-ext-native-driver/tree/sqlite-storage-native-driver)
Expand All @@ -243,8 +246,8 @@ See the [Sample section](#sample) for a sample with a more detailed explanation
- Windows platform version uses `UTF-16le` internal database encoding while the other platform versions use `UTF-8` internal encoding. (`UTF-8` internal encoding is preferred ref: [litehelpers/Cordova-sqlite-storage#652](https://github.com/litehelpers/Cordova-sqlite-storage/issues/652))
- Known issue with database names that contain certain US-ASCII punctuation and control characters (see below)
- The macOS platform version ("osx" platform) is not tested in a release build and should be considered pre-alpha.
- Android versions supported: 2.3.3 - 8.1, P (API levels 10 - 27, P), depending on Cordova version ref: <https://cordova.apache.org/docs/en/latest/guide/platforms/android/>
- iOS versions supported: 8.x / 9.x / 10.x / 11.x, see [deviations section](#deviations) below for differences in case of WKWebView (using cordova-plugin-wkwebview-engine)
- Android versions supported: 3.0 - 9.0 (API level 11 - 28), depending on Cordova version ref: <https://cordova.apache.org/docs/en/latest/guide/platforms/android/>
- iOS versions supported: 8.x / 9.x / 10.x / 11.x / 12.x (see [deviations section](#deviations) below for differences in case of WKWebView)
- FTS3, FTS4, and R-Tree are fully tested and supported for all target platforms in this version branch.
- Default `PRAGMA journal_mode` setting (*tested*):
- Android use of the `androidDatabaseProvider: 'system'` setting: `persist` (pre-8.0) / `truncate` (Android 8.0, 8.1) / `wal` (Android Pie)
Expand All @@ -258,6 +261,7 @@ See the [Sample section](#sample) for a sample with a more detailed explanation

- Using recent version of SQLite3 (`3.26.0`) with a security update ([litehelpers/Cordova-sqlite-storage#837](https://github.com/litehelpers/Cordova-sqlite-storage/issues/837)) and window functions
- Using `SQLITE_DEFAULT_SYNCHRONOUS=3` (EXTRA DURABLE) build setting to be extra robust against possible database corruption ref: [litehelpers/Cordova-sqlite-storage#736](https://github.com/litehelpers/Cordova-sqlite-storage/issues/736)
- `SQLITE_DBCONFIG_DEFENSIVE` flag is used for extra SQL safety, as described above
- Nice overview of alternatives for storing local data in Cordova apps at: <https://www.sitepoint.com/storing-local-data-in-a-cordova-app/>
- New alternative solution for small data storage: [TheCocoaProject / cordova-plugin-nativestorage](https://github.com/TheCocoaProject/cordova-plugin-nativestorage) - simpler "native storage of variables" for Android/iOS/Windows
- Resolved Java 6/7/8 concurrent map compatibility issue reported in [litehelpers/Cordova-sqlite-storage#726](https://github.com/litehelpers/Cordova-sqlite-storage/issues/726), THANKS to pointer by [@NeoLSN (Jason Yang/楊朝傑)](https://github.com/NeoLSN) in [litehelpers/Cordova-sqlite-storage#727](https://github.com/litehelpers/Cordova-sqlite-storage/issues/727).
Expand Down
3 changes: 1 addition & 2 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
# (done)

else
# openDatabase step 1:
console.log 'OPEN database: ' + @dbname

opensuccesscb = =>
Expand Down Expand Up @@ -505,7 +506,6 @@
error: handlerFor(i, false)

tropts.push
qid: null # TBD NEEDED to pass @brodybits/Cordova-sql-test-app for some reason
sql: request.sql
params: request.params

Expand All @@ -517,7 +517,6 @@
for resultIndex in [0 .. result.length-1]
r = result[resultIndex]
type = r.type
# NOTE: r.qid can be ignored
res = r.result

q = mycbmap[resultIndex]
Expand Down
2 changes: 1 addition & 1 deletion bin/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ try {
echo "compiled coffeescript to javascript"

# move everything to a temp folder to avoid infinite recursion errors
if (test-path ../.plugin) {
if (test-path ../.plugin) {
rm -force -recurse ../.plugin -ErrorAction ignore
}
mkdir -ErrorAction ignore ../.plugin | out-null
Expand Down
Empty file removed node_modules/.keep
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"start": "node scripts/prepareSpec.js"
},
"devDependencies": {
"shelljs": "^0.7.4"
"shelljs": "^0.8.3"
}
}
32 changes: 13 additions & 19 deletions scripts/beforePluginInstall.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
#!/usr/bin/env node

// Adapted from:
// https://github.com/AllJoyn-Cordova/cordova-plugin-alljoyn/blob/master/scripts/beforePluginInstall.js

var path = require('path');
var exec = require('child_process').exec;

// XXX TODO auto-detect:
var package_name = 'cordova-sqlite-ext-common-core';
const path = require('path');
const exec = require('child_process').exec;

module.exports = function (context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();
const packageName = require('../package.json').name;

console.log('installing external dependencies via npm');
module.exports = function () {
return new Promise(function (resolve, reject) {
console.log('installing external dependencies via npm');
console.log('for package name: ' + packageName);

exec( 'npm install', {cwd: path.join('plugins', package_name)},
exec('npm install', { cwd: path.join('plugins', packageName) },
function (error, stdout, stderr) {
if (error !== null) {
// XXX TODO SIGNAL FAILURE HERE.
console.log('npm install of external dependencies failed: ' + error);
deferral.resolve();
console.log('npm install of external dependencies failed with error message: ' + error.message);
reject();
} else {
console.log('npm install of external dependencies ok');
deferral.resolve();
resolve();
}
}
);

return deferral.promise;
);
});
};
11 changes: 8 additions & 3 deletions spec/www/spec/db-tx-error-mapping-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var mytests = function() {
});
}, MYTIMEOUT);

it(suiteName + 'INSERT with VALUES in the wrong place (with a trailing space) [XXX TBD "incomplete input" vs "syntax error" message on (WebKit) Web SQL on Android 8.x/...]', function(done) {
it(suiteName + 'INSERT with VALUES in the wrong place (with a trailing space) [XXX TBD "incomplete input" vs "syntax error" message on (WebKit) Web SQL on Android 8.x/XXX]', function(done) {
var db = openDatabase("INSERT-Syntax-error-test.db", "1.0", "Demo", DEFAULT_SIZE);
expect(db).toBeDefined();

Expand Down Expand Up @@ -200,22 +200,27 @@ var mytests = function() {
else
expect(error.code).toBe(5);

/* ** XXX TODO NEEDS TO BE UPDATED:
if (isWebSql && (/Android [7-9]/.test(navigator.userAgent)))
expect(error.message).toMatch(/could not prepare statement.*/); // XXX TBD incomplete input vs syntax error message on Android 8(+)
expect(error.message).toMatch(/could not prepare statement.*.../); // XXX TBD incomplete input vs syntax error message on Android 8(+)/XXX
else if (isWebSql && !isChromeBrowser && !(/Android 4.[1-3]/.test(navigator.userAgent)))
expect(error.message).toMatch(/could not prepare statement.*1 near \"VALUES\": syntax error/);
else if (isWebSql && isBrowser)
expect(error.message).toMatch(/could not prepare statement.*1 incomplete input/);
else if (isWebSql)
expect(error.message).toMatch(/near \"VALUES\": syntax error/);
// XXX ... */
if (isWebSql)
expect(error.message).toMatch(/could not prepare statement.*/); // XXX TBD incomplete input vs syntax error message on Android 8(+) & iOS 12(+)
else if (isWindows)
expect(error.message).toMatch(/Error preparing an SQLite statement/);
else if (isAndroid && !isImpl2)
expect(error.message).toMatch(/sqlite3_prepare_v2 failure:.*incomplete input/);
else if (isAndroid && isImpl2)
expect(error.message).toMatch(/near \"VALUES\": syntax error.*code 1.*while compiling: INSERT INTO test_table/);
else
expect(error.message).toMatch(/incomplete input/);
//* XXX ...
expect(error.message).toMatch(/incomplete input/); // XXX SQLite 3.22.0

// FAIL transaction & check reported transaction error:
return true;
Expand Down
37 changes: 27 additions & 10 deletions src/android/io/sqlc/SQLiteAndroidDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package io.sqlc;

import android.annotation.SuppressLint;

import android.database.Cursor;
import android.database.CursorWindow;

Expand Down Expand Up @@ -70,6 +68,14 @@ class SQLiteAndroidDatabase
* @param dbfile The database File specification
*/
void open(File dbfile) throws Exception {
if (!isPostHoneycomb) {
Log.v("SQLiteAndroidDatabase.open",
"INTERNAL PLUGIN ERROR: deprecated android.os.Build.VERSION not supported: " +
android.os.Build.VERSION.SDK_INT);
throw new RuntimeException(
"INTERNAL PLUGIN ERROR: deprecated android.os.Build.VERSION not supported: " +
android.os.Build.VERSION.SDK_INT);
}
dbFile = dbfile; // for possible bug workaround
mydb = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
}
Expand Down Expand Up @@ -124,7 +130,6 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparamsArr, CallbackConte
cbc.success(batchResults);
}

@SuppressLint("NewApi")
private void executeSqlBatchStatement(String query, JSONArray json_params, JSONArray batchResults) {

if (mydb == null) {
Expand All @@ -149,7 +154,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
//Log.v("executeSqlBatch", "query type: " + queryType);

if (queryType == QueryType.update || queryType == queryType.delete) {
if (isPostHoneycomb) {
// if (isPostHoneycomb) {
SQLiteStatement myStatement = mydb.compileStatement(query);

if (json_params != null) {
Expand Down Expand Up @@ -181,7 +186,10 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
// Assuming SDK_INT was lying & method not found:
// do nothing here & try again with raw query.
ex.printStackTrace();
Log.v("executeSqlBatch", "SQLiteStatement.executeUpdateDelete(): runtime error (fallback to old API): " + errorMessage);
// Log.v("executeSqlBatch", "SQLiteStatement.executeUpdateDelete(): runtime error (fallback to old API): " + errorMessage);
Log.v("SQLiteAndroidDatabase.executeSqlBatchStatement",
"INTERNAL PLUGIN ERROR: could not do myStatement.executeUpdateDelete(): " + ex.getMessage());
throw(ex);
}

// "finally" cleanup myStatement
Expand All @@ -191,7 +199,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
queryResult = new JSONObject();
queryResult.put("rowsAffected", rowsAffected);
}
}
// }

if (needRawQuery) { // for pre-honeycomb behavior
rowsAffectedCompat = countRowsAffectedCompat(queryType, query, json_params, mydb);
Expand Down Expand Up @@ -472,15 +480,23 @@ private JSONObject executeSqlStatementQuery(SQLiteDatabase mydb, String query,
key = cur.getColumnName(i);

if (isPostHoneycomb) {

// Use try & catch just in case android.os.Build.VERSION.SDK_INT >= 11 is lying:
try {
bindPostHoneycomb(row, key, cur, i);
} catch (Exception ex) {
bindPreHoneycomb(row, key, cur, i);
// bindPreHoneycomb(row, key, cur, i);
Log.v("SQLiteAndroidDatabase.executeSqlStatementQuery",
"INTERNAL PLUGIN ERROR: could not bindPostHoneycomb: " + ex.getMessage());
throw(ex);
}
} else {
bindPreHoneycomb(row, key, cur, i);
// NOT EXPECTED:
// bindPreHoneycomb(row, key, cur, i);
Log.v("SQLiteAndroidDatabase.executeSqlStatementQuery",
"INTERNAL PLUGIN ERROR: deprecated android.os.Build.VERSION not supported: " + android.os.Build.VERSION.SDK_INT);
throw new RuntimeException(
"INTERNAL PLUGIN ERROR: deprecated android.os.Build.VERSION not supported: " +
android.os.Build.VERSION.SDK_INT);
}
}

Expand All @@ -505,7 +521,6 @@ private JSONObject executeSqlStatementQuery(SQLiteDatabase mydb, String query,
return rowsResult;
}

@SuppressLint("NewApi")
private void bindPostHoneycomb(JSONObject row, String key, Cursor cur, int i) throws JSONException {
int curType = cur.getType(i);

Expand All @@ -526,6 +541,7 @@ private void bindPostHoneycomb(JSONObject row, String key, Cursor cur, int i) th
}
}

/* ** NO LONGER SUPPORTED:
private void bindPreHoneycomb(JSONObject row, String key, Cursor cursor, int i) throws JSONException {
// Since cursor.getType() is not available pre-honeycomb, this is
// a workaround so we don't have to bind everything as a string
Expand All @@ -544,6 +560,7 @@ private void bindPreHoneycomb(JSONObject row, String key, Cursor cursor, int i)
row.put(key, cursor.getString(i));
}
}
// */

static QueryType getQueryType(String query) {
Matcher matcher = FIRST_WORD.matcher(query);
Expand Down
2 changes: 0 additions & 2 deletions src/android/io/sqlc/SQLiteConnectorDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package io.sqlc;

import android.annotation.SuppressLint;

import android.util.Log;

import java.io.File;
Expand Down
6 changes: 2 additions & 4 deletions src/android/io/sqlc/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package io.sqlc;

import android.annotation.SuppressLint;

import android.util.Log;

import java.io.File;
Expand All @@ -30,7 +28,7 @@
public class SQLitePlugin extends CordovaPlugin {

/**
* Multiple database runner map (static).
* Concurrent database runner map.
*
* NOTE: no public static accessor to db (runner) map since it is not
* expected to work properly with db threading.
Expand All @@ -44,7 +42,7 @@ public class SQLitePlugin extends CordovaPlugin {
* THANKS to @NeoLSN (Jason Yang/楊朝傑) for giving the pointer in:
* https://github.com/litehelpers/Cordova-sqlite-storage/issues/727
*/
static Map<String, DBRunner> dbrmap = new ConcurrentHashMap<String, DBRunner>();
private Map<String, DBRunner> dbrmap = new ConcurrentHashMap<String, DBRunner>();

/**
* NOTE: Using default constructor, no explicit constructor.
Expand Down
Loading

0 comments on commit 1794f4e

Please sign in to comment.