Skip to content

Commit

Permalink
cordova-sqlite-storage 2.0.4 - merge release
Browse files Browse the repository at this point in the history
Merge branch 'cordova-sqlite-legacy-express-core' into storage-master
  • Loading branch information
Christopher J. Brody committed May 4, 2017
2 parents 843b056 + 8016cdd commit 952e92b
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 95 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-storage 2.0.4

###### cordova-sqlite-legacy-express-core 1.0.0

- Workaround solution to BUG litehelpers/Cordova-sqlite-storage#666 (hanging transaction in case of location reload/change)
- selfTest simulate scenario & test solution to BUG litehelpers/Cordova-sqlite-storage#666 (also includes string test and test of effects of location reload/change in this version branch, along with another internal check)

## cordova-sqlite-storage 2.0.3

- Drop engines rule from package.json
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ See the [Sample section](#sample) for a sample with a more detailed explanation.
- This version supports the use of two (2) possible Android sqlite database implementations:
- default: lightweight [Android-sqlite-connector](https://github.com/liteglue/Android-sqlite-connector)
- optional: built-in Android database classes (usage described below)
- Windows 8.1 and Windows Phone 8.1 are no longer supported by this version. WP8 and Windows 8.1/Windows Phone 8.1/Windows 10 support for Visual Studio 2015 is available in: [litehelpers / Cordova-sqlite-legacy-build-support](https://github.com/litehelpers/Cordova-sqlite-legacy-build-support)
- Support for WP8 along with Windows 8.1/Windows Phone 8.1/Windows 10 using Visual Studio 2015 is available in [litehelpers / Cordova-sqlite-legacy](https://github.com/litehelpers/Cordova-sqlite-legacy).
- The following features are available in [litehelpers / cordova-sqlite-ext](https://github.com/litehelpers/cordova-sqlite-ext):
- REGEXP (Android/iOS/macOS)
- SELECT BLOB data in Base64 format (all platforms Android/iOS/macOS/Windows)
Expand All @@ -144,6 +144,7 @@ See the [Sample section](#sample) for a sample with a more detailed explanation.
- It is **not** possible to use this plugin with the default "Any CPU" target. A specific target CPU type **must** be specified when building an app with this plugin.
- This version has dependency on platform toolset libraries included by Visual Studio 2017 ([litehelpers/Cordova-sqlite-storage#580](https://github.com/litehelpers/Cordova-sqlite-storage/issues/580)). Visual Studio 2015 is now supported by [litehelpers / Cordova-sqlite-legacy-build-support](https://github.com/litehelpers/Cordova-sqlite-legacy-build-support).
- 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))
- Certain close/delete scenarios in the test suite not working on Windows
- The macOS platform version ("osx" platform) has not been tested in a release build and should be considered pre-alpha.
- FTS3, FTS4, and R-Tree support is tested working OK in this version (for all target platforms in this version branch Android/iOS/macOS/Windows)
- Android is supported back to SDK 10 (a.k.a. Gingerbread, Android 2.3.3); support for older versions is available upon request.
Expand All @@ -154,6 +155,7 @@ See the [Sample section](#sample) for a sample with a more detailed explanation.

## Announcements

- 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)
- This version references Windows platform toolset v141 to support Visual Studio 2017. Visual Studio 2015 is now supported by [litehelpers / Cordova-sqlite-legacy-build-support](https://github.com/litehelpers/Cordova-sqlite-legacy-build-support).
- [brodybits / cordova-sqlite-storage-starter-app](https://github.com/brodybits/cordova-sqlite-storage-starter-app) project is a CC0 (public domain) starting point and may also be used to reproduce issues with this plugin. In addition [brodybits / cordova-sqlite-test-app](https://github.com/brodybits/cordova-sqlite-test-app) may be used to reproduce issues with other versions of this plugin.
- The Lawnchair adapter is now moved to [litehelpers / cordova-sqlite-lawnchair-adapter](https://github.com/litehelpers/cordova-sqlite-lawnchair-adapter).
Expand All @@ -175,11 +177,11 @@ See the [Sample section](#sample) for a sample with a more detailed explanation.

- Drop-in replacement for HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/): the only change should be to replace the static `window.openDatabase()` factory call with `window.sqlitePlugin.openDatabase()`, with parameters as documented below. Known deviations are documented in the [deviations section](#deviations) below.
- Failure-safe nested transactions with batch processing optimizations (according to HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/))
- API (based on HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/)) is designed to be as flexible as possible but does not allow any transactions to be kept hanging open.
- API (based on HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/)) is designed to be as flexible as possible but does not allow any transactions to _remain_ 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.
- No arbitrary size limit. SQLite limits described at: <http://www.sqlite.org/limits.html>
- Also tested with multi-page applications (XXX BUG: possible transaction issue after window.location (page) change, with possible data loss ref: [litehelpers/Cordova-sqlite-storage#666](https://github.com/litehelpers/Cordova-sqlite-storage/issues/666))
- Also tested for multi-page applications with window location changes
- This project is self-contained though with sqlite3 dependencies auto-fetched by npm. There are no dependencies on other plugins such as cordova-plugin-file.
- Windows platform version uses a customized version of the performant [doo / SQLite3-WinRT](https://github.com/doo/SQLite3-WinRT) C++ 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)
Expand Down
140 changes: 116 additions & 24 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# applications that repeatedly open and close the database.
# [BUG #210] TODO: better to abort and clean up the pending transaction state.
# XXX TBD this will be renamed and include some more per-db state.
# NOTE: In case txLocks is renamed or replaced the selfTest has to be adapted as well.
txLocks = {}

## utility functions:
Expand Down Expand Up @@ -83,7 +84,7 @@
SQLitePlugin = (openargs, openSuccess, openError) ->
# console.log "SQLitePlugin openargs: #{JSON.stringify openargs}"

# _should_ already be checked by openDatabase:
# SHOULD already be checked by openDatabase:
if !(openargs and openargs['name'])
throw newSQLError "Cannot create a SQLitePlugin db instance without a db name"

Expand Down Expand Up @@ -114,8 +115,9 @@
SQLitePlugin::databaseFeatures = isSQLitePluginDatabase: true

# Keep track of state of open db connections
# XXX TBD this will be moved and renamed or
# combined with txLocks.
# XXX FUTURE TBD this *may* be moved and renamed,
# or even combined with txLocks if possible.
# NOTE: In case txLocks is renamed or replaced the selfTest has to be adapted as well.
SQLitePlugin::openDBs = {}

SQLitePlugin::addTransaction = (t) ->
Expand All @@ -126,14 +128,17 @@
}
txLocks[@dbname].queue.push t
if @dbname of @openDBs && @openDBs[@dbname] isnt DB_STATE_INIT
# XXX TODO: only when queue has length of 1 [and test it!!]
# FUTURE TBD: rename startNextTransaction to something like
# triggerTransactionQueue
# ALT TBD: only when queue has length of 1 (and test)??
@startNextTransaction()

else
if @dbname of @openDBs
console.log 'new transaction is waiting for open operation'
else
# XXX TBD TODO: in this case (which should not happen), should abort and discard the transaction.
# XXX SHOULD NOT GET HERE.
# FUTURE TBD TODO: in this exceptional case abort and discard the transaction.
console.log 'database is closed, new transaction is [stuck] waiting until db is opened again!'
return

Expand Down Expand Up @@ -218,7 +223,7 @@
#if !@openDBs[@dbname] then call open error cb, and abort pending tx if any
if !@openDBs[@dbname]
console.log 'database was closed during open operation'
# XXX TODO [BUG #210] (and test!!):
# XXX TODO (WITH TEST) ref BUG litehelpers/Cordova-sqlite-storage#210:
# if !!error then error newSQLError 'database closed during open operation'
# @abortAllPendingTransactions()

Expand All @@ -243,27 +248,49 @@
# store initial DB state:
@openDBs[@dbname] = DB_STATE_INIT

# As a WORKAROUND SOLUTION to BUG litehelpers/Cordova-sqlite-storage#666:
# 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.
if not txLocks[@dbname]
myfn = (tx) ->
tx.addStatement 'ROLLBACK'
return
@addTransaction new SQLitePluginTransaction @, myfn, null, null, false, false

cordova.exec opensuccesscb, openerrorcb, "SQLitePlugin", "open", [ @openargs ]

return

SQLitePlugin::close = (success, error) ->
if @dbname of @openDBs
if txLocks[@dbname] && txLocks[@dbname].inProgress
# XXX TBD: wait for current tx then close (??)
# FUTURE TBD TODO ref BUG litehelpers/Cordova-sqlite-storage#210:
# Wait for current tx to finish then close,
# then abort any other pending transactions
# (and cleanup any other internal resources).
# (This would need testing!!)
console.log 'cannot close: transaction is in progress'
error newSQLError 'database cannot be closed while a transaction is in progress'
return

console.log 'CLOSE database: ' + @dbname

# XXX [BUG #209] closing one db handle disables other handles to same db
# NOTE: closing one db handle disables other handles to same db
# FUTURE TBD TODO ref litehelpers/Cordova-sqlite-storage#210:
# Add a dispose method to simply invalidate the
# current database object ("this")
delete @openDBs[@dbname]

if txLocks[@dbname] then console.log 'closing db with transaction queue length: ' + txLocks[@dbname].queue.length
else console.log 'closing db with no transaction lock state'

# XXX [BUG #210] TODO: when closing or deleting a db, abort any pending transactions [and test it!!]
# XXX TODO BUG litehelpers/Cordova-sqlite-storage#210:
# abort all pending transactions (with error callback)
# when closing a database (needs testing!!)
# (and cleanup any other internal resources)

cordova.exec success, error, "SQLitePlugin", "close", [ { path: @dbname } ]

Expand Down Expand Up @@ -657,6 +684,12 @@
new SQLitePlugin openargs, okcb, errorcb

deleteDatabase: (first, success, error) ->
# XXX TODO BUG litehelpers/Cordova-sqlite-storage#367:
# abort all pending transactions (with error callback)
# when deleting a database
# (and cleanup any other internal resources)
# NOTE: This should properly close the database
# (at least on the JavaScript side) before deleting.
args = {}

if first.constructor == String
Expand Down Expand Up @@ -696,7 +729,10 @@

args.dblocation = dblocation

# XXX [BUG #210] TODO: when closing or deleting a db, abort any pending transactions (with error callback)
# XXX TODO BUG litehelpers/Cordova-sqlite-storage#367 (repeated here):
# abort all pending transactions (with error callback)
# when deleting a database
# (and cleanup any other internal resources)
delete SQLitePlugin::openDBs[args.path]
cordova.exec success, error, "SQLitePlugin", "delete", [ args ]

Expand All @@ -707,11 +743,11 @@

start: (successcb, errorcb) ->
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'},
(-> SelfTest.start2(successcb, errorcb)),
(-> SelfTest.start2(successcb, errorcb))
(-> SelfTest.step1(successcb, errorcb)),
(-> SelfTest.step1(successcb, errorcb))
return

start2: (successcb, errorcb) ->
step1: (successcb, errorcb) ->
SQLiteFactory.openDatabase {name: SelfTest.DBNAME, location: 'default'}, (db) ->
check1 = false
db.transaction (tx) ->
Expand All @@ -732,36 +768,78 @@

if resutSet.rows.item(0).upperText isnt 'TEST'
return SelfTest.finishWithError errorcb,
"Incorrect resutSet.rows.item(0).upperText value: #{resutSet.rows.item(0).data} (expected: 'TEST')"
"Incorrect resutSet.rows.item(0).upperText value: #{resutSet.rows.item(0).upperText} (expected: 'TEST')"

check1 = true
return

, (sql_err) ->
SelfTest.finishWithError errorcb, "SQL error: #{sql_err}"
return
, (ignored, tx_sql_err) ->
return SelfTest.finishWithError errorcb, "TX SQL error: #{tx_sql_err}"

, (tx_err) ->
SelfTest.finishWithError errorcb, "TRANSACTION error: #{tx_err}"
return

, (tx_err) ->
return SelfTest.finishWithError errorcb, "TRANSACTION error: #{tx_err}"

, () ->
# tx success:
if !check1
return SelfTest.finishWithError errorcb,
'Did not get expected upperText result data'

# DELETE INTERNAL STATE to simulate the effects of location refresh or change:
delete db.openDBs[SelfTest.DBNAME]
delete txLocks[SelfTest.DBNAME]
# SIMULATE SCENARIO IN BUG litehelpers/Cordova-sqlite-storage#666:
db.executeSql 'BEGIN', null, (ignored) -> nextTick -> # (nextTick needed for Windows)
# DELETE INTERNAL STATE to simulate the effects of location refresh or change:
delete db.openDBs[SelfTest.DBNAME]
delete txLocks[SelfTest.DBNAME]
nextTick ->
# VERIFY INTERNAL STATE IS DELETED:
db.transaction (tx2) ->
tx2.executeSql 'SELECT 1'
return
, (tx_err) ->
# EXPECTED RESULT:
if !tx_err
return SelfTest.finishWithError errorcb, 'Missing error object'
SelfTest.step2 successcb, errorcb
return
, () ->
# NOT EXPECTED:
return SelfTest.finishWithError errorcb, 'Missing error object'
return
return

SelfTest.start3 successcb, errorcb
return
return

, (open_err) ->
SelfTest.finishWithError errorcb, "Open database error: #{open_err}"
return

step2: (successcb, errorcb) ->
SQLiteFactory.openDatabase {name: SelfTest.DBNAME, location: 'default'}, (db) ->
# TX SHOULD SUCCEED to demonstrate solution to BUG litehelpers/Cordova-sqlite-storage#666:
db.transaction (tx) ->
tx.executeSql 'SELECT ? AS myResult', [null], (ignored, resutSet) ->
if !resutSet.rows
return SelfTest.finishWithError errorcb, 'Missing resutSet.rows'
if !resutSet.rows.length
return SelfTest.finishWithError errorcb, 'Missing resutSet.rows.length'
if resutSet.rows.length isnt 1
return SelfTest.finishWithError errorcb,
"Incorrect resutSet.rows.length value: #{resutSet.rows.length} (expected: 1)"
SelfTest.step3 successcb, errorcb
return
return
, (txError) ->
# NOT EXPECTED:
return SelfTest.finishWithError errorcb, "UNEXPECTED TRANSACTION ERROR: #{txError}"
return
, (open_err) ->
SelfTest.finishWithError errorcb, "Open database error: #{open_err}"
return

start3: (successcb, errorcb) ->
step3: (successcb, errorcb) ->
SQLiteFactory.openDatabase {name: SelfTest.DBNAME, location: 'default'}, (db) ->
db.sqlBatch [
'CREATE TABLE TestTable(id integer primary key autoincrement unique, data);'
Expand Down Expand Up @@ -878,10 +956,21 @@
# CLEANUP & FINISH:
db.close () ->
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, (cleanup_err)->
# TBD IGNORE THIS ERROR on Windows (and WP8):
if /Windows /.test(navigator.userAgent) or /IEMobile/.test(navigator.userAgent)
console.log "IGNORE CLEANUP (DELETE) ERROR: #{JSON.stringify cleanup_err} (Windows/WP8)"
successcb()
return
SelfTest.finishWithError errorcb, "Cleanup error: #{cleanup_err}"

, (close_err) ->
# TBD IGNORE THIS ERROR on Windows (and WP8):
if /Windows /.test(navigator.userAgent) or /IEMobile/.test(navigator.userAgent)
console.log "IGNORE close ERROR: #{JSON.stringify close_err} (Windows/WP8)"
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, successcb
return
SelfTest.finishWithError errorcb, "close error: #{close_err}"
# FUTURE TODO: return

, (select_err) ->
SelfTest.finishWithError errorcb, "SELECT error: #{select_err}"
Expand All @@ -894,8 +983,11 @@
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

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.0.3",
"version": "2.0.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.0.3">
version="2.0.4">

<name>Cordova sqlite storage plugin</name>

Expand Down
2 changes: 0 additions & 2 deletions spec/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<!-- [Cordova] source file(s): -->
<script src="cordova.js"></script>
<!-- Needed for Cordova pre-3.0: -->
<script src="SQLitePlugin.js"></script>

<!-- spec file(s): -->
<script src="spec/browser-check-startup.js"></script>
Expand Down
Loading

0 comments on commit 952e92b

Please sign in to comment.