Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…r-adapter into outsystems

# Conflicts:
#	package.json
#	plugin.xml
#	src/android/sqlcipher/libs/arm64-v8a/libsqlcipher.so
#	src/android/sqlcipher/libs/armeabi-v7a/libsqlcipher.so
#	src/android/sqlcipher/libs/armeabi/libsqlcipher.so
#	src/android/sqlcipher/libs/sqlcipher.jar
#	src/android/sqlcipher/libs/x86/libsqlcipher.so
#	src/android/sqlcipher/libs/x86_64/libsqlcipher.so
  • Loading branch information
usernuno committed Dec 13, 2018
2 parents 078017f + d1e2eef commit 28c8c27
Show file tree
Hide file tree
Showing 37 changed files with 1,198 additions and 640 deletions.
50 changes: 50 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
# Changes

## cordova-sqlcipher-adapter 0.1.11

##### 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

##### cordova-sqlite-legacy-core 1.0.5

###### 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.
- selfTest database cleanup do not ignore close or delete error on any platforms

## cordova-sqlcipher-adapter 0.1.10

- Windows 8.1 and Windows Phone 8.1 supported again, NOW DEPRECATED

##### cordova-sqlite-legacy-core 1.0.4

- New workaround solution to BUG 666: close db before opening (ignore close error)

##### cordova-sqlite-legacy-core 1.0.3

- Suppress warnings when building sqlite3.c & PSPDFThreadSafeMutableDictionary.m on iOS/macOS

##### cordova-sqlite-legacy-core 1.0.2

- Fix log in case of transaction waiting for open to finish; doc fixes
- SQLite 3.15.2 build with SQLITE_THREADSAFE=2 on iOS/macOS (SQLITE_THREADSAFE=1 on Android/Windows) and other flag fixes in this version branch to avoid possible malformed database due to multithreaded access ref: litehelpers/Cordova-sqlite-storage#703
- Windows 10 (UWP) build with /SAFESEH flag on Win32 (x86) target

###### cordova-sqlite-legacy-express-core 1.0.2

- Use PSPDFThreadSafeMutableDictionary for iOS/macOS to avoid threading issue ref: litehelpers/Cordova-sqlite-storage#716

###### cordova-sqlite-legacy-express-core 1.0.1

- Fix bug 666 workaround to trigger ROLLBACK in the next event tick (needed to support version with pre-populated database on Windows)

###### 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)
- Drop engine constraints in package.json & plugin.xml (in this version branch)
- Remove Lawnchair adapter from this version branch
- Support macOS platform with builtin libsqlite3.dylib framework in this version branch

## cordova-sqlcipher-adapter 0.1.9

- SQLCipher 3.4.1, SQLCipher for Android 3.5.6
Expand Down
2 changes: 2 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ MIT only

based on Phonegap-SQLitePlugin by @davibe (Davide Bertola <[email protected]>) and @joenoon (Joe Noon <[email protected]>)

includes and uses PSPDFThreadSafeMutableDictionary (PSPDFThreadSafeMutableDictionary.m <https://gist.github.com/steipete/5928916>) MIT license by @steipete (<https://gist.github.com/steipete>)

## Windows version

MIT or Apache 2.0
Expand Down
315 changes: 184 additions & 131 deletions README.md

Large diffs are not rendered by default.

154 changes: 125 additions & 29 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'
console.log 'new transaction is queued, waiting for open operation to finish'
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 @@ -208,6 +213,8 @@
success @
return

# (done)

else
console.log 'OPEN database: ' + @dbname

Expand All @@ -218,7 +225,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 +250,46 @@
# store initial DB state:
@openDBs[@dbname] = DB_STATE_INIT

cordova.exec opensuccesscb, openerrorcb, "SQLitePlugin", "open", [ @openargs ]
# 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

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 +683,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 +728,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 +742,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,37 +767,80 @@

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

start3: (successcb, errorcb) ->
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

step3: (successcb, errorcb) ->
SQLiteFactory.openDatabase {name: SelfTest.DBNAME, location: 'default'}, (db) ->
# FUTURE TBD TEST CRUD OPERATIONS (already fixed in a newer version branch)
db.sqlBatch [
'CREATE TABLE TestTable(id integer primary key autoincrement unique, data);'
[ 'INSERT INTO TestTable (data) VALUES (?);', ['test-value'] ]
Expand Down Expand Up @@ -832,6 +910,7 @@

, (tx2_err) ->
SelfTest.finishWithError errorcb, "readTransaction error: #{tx2_err}"

, () ->
if !readTransactionFinished
SelfTest.finishWithError errorcb, 'readTransaction did not finish'
Expand Down Expand Up @@ -875,13 +954,18 @@
if !secondReadTransactionFinished
SelfTest.finishWithError errorcb, 'second readTransaction did not finish'
return

# CLEANUP & FINISH:
db.close () ->
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, (cleanup_err)->
SelfTest.finishWithError errorcb, "Cleanup error: #{cleanup_err}"
SelfTest.cleanupAndFinish successcb, errorcb
return

, (close_err) ->
# DO NOT IGNORE CLOSE ERROR ON ANY PLATFORM:
SelfTest.finishWithError errorcb, "close error: #{close_err}"
return

return

, (select_err) ->
SelfTest.finishWithError errorcb, "SELECT error: #{select_err}"
Expand All @@ -893,10 +977,22 @@
SelfTest.finishWithError errorcb, "Open database error: #{open_err}"
return

cleanupAndFinish: (successcb, errorcb) ->
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, successcb, (cleanup_err)->
# DO NOT IGNORE CLEANUP DELETE ERROR ON ANY PLATFORM:
SelfTest.finishWithError errorcb, "CLEANUP DELETE ERROR: #{cleanup_err}"
return
return

finishWithError: (errorcb, message) ->
console.log "selfTest ERROR with message: #{message}"
SQLiteFactory.deleteDatabase {name: SelfTest.DBNAME, location: 'default'}, ->
errorcb newSQLError message
, (err2)-> errorcb newSQLError "Cleanup error: #{err2} for error: #{message}"
return
, (err2)->
console.log "selfTest CLEANUP DELETE ERROR #{err2}"
errorcb newSQLError "CLEANUP DELETE ERROR: #{err2} for error: #{message}"
return
return

## Exported API:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "cordova-sqlcipher-adapter",
"version": "0.1.9+os",
"version": "0.1.11-OS",
"description": "SQLCipher database adapter for PhoneGap/Cordova, based on cordova-sqlite-storage",
"cordova": {
"id": "cordova-sqlcipher-adapter",
"platforms": [
"android",
"ios",
"osx",
"windows"
]
},
Expand All @@ -20,6 +21,7 @@
"ecosystem:cordova",
"cordova-android",
"cordova-ios",
"cordova-osx",
"cordova-windows"
],
"author": "various",
Expand Down
Loading

0 comments on commit 28c8c27

Please sign in to comment.