@capacitor-community/sqlite 3.5.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +2 -1
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +19 -0
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +24 -0
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +4 -2
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +8 -1
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +34 -1
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSecret.java +21 -0
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +1 -1
  9. package/dist/esm/definitions.d.ts +14 -0
  10. package/dist/esm/definitions.js +9 -0
  11. package/dist/esm/definitions.js.map +1 -1
  12. package/dist/esm/web.d.ts +1 -0
  13. package/dist/esm/web.js +4 -0
  14. package/dist/esm/web.js.map +1 -1
  15. package/dist/plugin.cjs.js +13 -0
  16. package/dist/plugin.cjs.js.map +1 -1
  17. package/dist/plugin.js +13 -0
  18. package/dist/plugin.js.map +1 -1
  19. package/electron/dist/plugin.js +65 -10
  20. package/electron/dist/plugin.js.map +1 -1
  21. package/ios/Plugin/CapacitorSQLite.swift +26 -0
  22. package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
  23. package/ios/Plugin/CapacitorSQLitePlugin.swift +20 -0
  24. package/ios/Plugin/Database.swift +4 -1
  25. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +9 -1
  26. package/ios/Plugin/Utils/UtilsJson.swift +30 -2
  27. package/ios/Plugin/Utils/UtilsSQLCipher.swift +5 -1
  28. package/ios/Plugin/Utils/UtilsSecret.swift +20 -1
  29. package/package.json +6 -6
@@ -231,6 +231,32 @@ enum CapacitorSQLiteError: Error {
231
231
  // swiftlint:enable no_space_in_method_call
232
232
  // swiftlint:enable function_body_length
233
233
 
234
+ // MARK: - ClearEncryptionSecret
235
+
236
+ @objc public func clearEncryptionSecret() throws {
237
+ if isInit {
238
+ if isEncryption {
239
+ do {
240
+ // close all connections
241
+ try closeAllConnections()
242
+ // set encryption secret
243
+ try UtilsSecret
244
+ .clearEncryptionSecret(prefix: prefixKeychain,
245
+ databaseLocation: databaseLocation)
246
+ return
247
+ } catch UtilsSecretError.clearEncryptionSecret(let message) {
248
+ throw CapacitorSQLiteError.failed(message: message)
249
+ } catch let error {
250
+ throw CapacitorSQLiteError.failed(message: "\(error)")
251
+ }
252
+ } else {
253
+ throw CapacitorSQLiteError.failed(message: "No Encryption set in capacitor.config")
254
+ }
255
+ } else {
256
+ throw CapacitorSQLiteError.failed(message: initMessage)
257
+ }
258
+ }
259
+
234
260
  // MARK: - getNCDatabasePath
235
261
 
236
262
  @objc public func getNCDatabasePath(_ folderPath: String, dbName: String ) throws -> String {
@@ -42,4 +42,5 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
42
42
  CAP_PLUGIN_METHOD(isSecretStored, CAPPluginReturnPromise);
43
43
  CAP_PLUGIN_METHOD(setEncryptionSecret, CAPPluginReturnPromise);
44
44
  CAP_PLUGIN_METHOD(changeEncryptionSecret, CAPPluginReturnPromise);
45
+ CAP_PLUGIN_METHOD(clearEncryptionSecret, CAPPluginReturnPromise);
45
46
  )
@@ -123,6 +123,26 @@ public class CapacitorSQLitePlugin: CAPPlugin {
123
123
  }
124
124
  }
125
125
 
126
+ // MARK: - ClearEncryptionSecret
127
+
128
+ @objc func clearEncryptionSecret(_ call: CAPPluginCall) {
129
+
130
+ do {
131
+ try implementation?.clearEncryptionSecret()
132
+ retHandler.rResult(call: call)
133
+ return
134
+ } catch CapacitorSQLiteError.failed(let message) {
135
+ let msg = "ClearEncryptionSecret: \(message)"
136
+ retHandler.rResult(call: call, message: msg)
137
+ return
138
+ } catch let error {
139
+ retHandler.rResult(
140
+ call: call,
141
+ message: "ClearEncryptionSecret: \(error)")
142
+ return
143
+ }
144
+ }
145
+
126
146
  // MARK: - CreateConnection
127
147
 
128
148
  @objc func createConnection(_ call: CAPPluginCall) {
@@ -467,7 +467,8 @@ class Database {
467
467
  if !isExists {
468
468
  // check if there are tables with last_modified column
469
469
  let isLastModified: Bool = try UtilsJson.isLastModified(mDB: self)
470
- if isLastModified {
470
+ let isSqlDeleted: Bool = try UtilsJson.isSqlDeleted(mDB: self)
471
+ if isLastModified && isSqlDeleted {
471
472
  let date = Date()
472
473
  let syncTime: Int = Int(date.timeIntervalSince1970)
473
474
  var stmt: String = "CREATE TABLE IF NOT EXISTS "
@@ -486,6 +487,8 @@ class Database {
486
487
  }
487
488
  } catch UtilsJsonError.isLastModified(let message) {
488
489
  throw DatabaseError.createSyncTable(message: message)
490
+ } catch UtilsJsonError.isSqlDeleted(let message) {
491
+ throw DatabaseError.createSyncTable(message: message)
489
492
  } catch UtilsJsonError.tableNotExists(let message) {
490
493
  throw DatabaseError.createSyncTable(message: message)
491
494
  } catch DatabaseError.executeSQL(let message) {
@@ -186,12 +186,15 @@ class ImportFromJson {
186
186
 
187
187
  // MARK: - ImportFromJson - CreateTableSchema
188
188
 
189
+ // swiftlint:disable function_body_length
190
+ // swiftlint:disable cyclomatic_complexity
189
191
  class func createTableSchema(mSchema: [JsonColumn],
190
192
  tableName: String, mode: String)
191
193
  -> [String] {
192
194
  var statements: [String] = []
193
195
  var stmt: String
194
196
  var isLastModified: Bool = false
197
+ var isSqlDeleted: Bool = false
195
198
  stmt = "CREATE TABLE IF NOT EXISTS "
196
199
  stmt.append(tableName)
197
200
  stmt.append(" (")
@@ -201,6 +204,9 @@ class ImportFromJson {
201
204
  if jSchColumn == "last_modified" {
202
205
  isLastModified = true
203
206
  }
207
+ if jSchColumn == "sql_deleted" {
208
+ isSqlDeleted = true
209
+ }
204
210
  stmt.append(jSchColumn)
205
211
  }
206
212
  }
@@ -222,7 +228,7 @@ class ImportFromJson {
222
228
  }
223
229
  stmt.append(");")
224
230
  statements.append(stmt)
225
- if isLastModified {
231
+ if isLastModified && isSqlDeleted {
226
232
  // create trigger last_modified associated with the table
227
233
  let triggerName: String = tableName + "_trigger_last_modified"
228
234
  stmt = "CREATE TRIGGER IF NOT EXISTS "
@@ -240,6 +246,8 @@ class ImportFromJson {
240
246
  }
241
247
  return statements
242
248
  }
249
+ // swiftlint:enable cyclomatic_complexity
250
+ // swiftlint:enable function_body_length
243
251
 
244
252
  // MARK: - ImportFromJson - CreateTableIndexes
245
253
 
@@ -18,6 +18,7 @@ enum UtilsJsonError: Error {
18
18
  case validateTriggers(message: String)
19
19
  case validateViews(message: String)
20
20
  case isLastModified(message: String)
21
+ case isSqlDeleted(message: String)
21
22
  case checkUpdate(message: String)
22
23
  case checkValues(message: String)}
23
24
 
@@ -81,6 +82,33 @@ class UtilsJson {
81
82
  return ret
82
83
  }
83
84
 
85
+ // MARK: - ImportFromJson - IsSqlDeleted
86
+
87
+ class func isSqlDeleted(mDB: Database) throws -> Bool {
88
+ var msg: String = "Error SqlDeleted: "
89
+ if !mDB.isDBOpen() {
90
+ msg.append("Database not opened")
91
+ throw UtilsJsonError.isSqlDeleted(message: msg)
92
+ }
93
+ var ret: Bool = false
94
+ do {
95
+ let tableList: [String] = try UtilsDrop.getTablesNames(mDB: mDB)
96
+ for table in tableList {
97
+ let namesTypes: JsonNamesTypes = try getTableColumnNamesTypes(mDB: mDB,
98
+ tableName: table)
99
+ if namesTypes.names.contains("sql_deleted") {
100
+ ret = true
101
+ break
102
+ }
103
+ }
104
+ } catch UtilsJsonError.getTableColumnNamesTypes(let message) {
105
+ throw UtilsJsonError.isSqlDeleted(message: message)
106
+ } catch UtilsDropError.getTablesNamesFailed(let message) {
107
+ throw UtilsJsonError.isSqlDeleted(message: message)
108
+ }
109
+ return ret
110
+ }
111
+
84
112
  // MARK: - ImportFromJson - IsViewExists
85
113
 
86
114
  class func isViewExists(mDB: Database, viewName: String)
@@ -117,9 +145,9 @@ class UtilsJson {
117
145
  throws -> JsonNamesTypes {
118
146
  var ret: JsonNamesTypes = JsonNamesTypes(names: [], types: [])
119
147
  var msg: String = "Error: getTableColumnNamesTypes "
120
- var query: String = "PRAGMA table_info("
148
+ var query: String = "PRAGMA table_info('"
121
149
  query.append(tableName)
122
- query.append(");")
150
+ query.append("');")
123
151
  do {
124
152
  var resQuery = try mDB.selectSQL(sql: query, values: [])
125
153
  if resQuery.count > 0 {
@@ -487,7 +487,9 @@ class UtilsSQLCipher {
487
487
  var sqlStmt = sql
488
488
  do {
489
489
  let isLast: Bool = try UtilsJson.isLastModified(mDB: mDB)
490
- if isLast {
490
+ let isDel: Bool = try UtilsJson.isSqlDeleted(mDB: mDB)
491
+ if isLast && isDel {
492
+ // Replace DELETE by UPDATE and set sql_deleted to 1
491
493
  if let range: Range<String.Index> = sql
492
494
  .range(of: "WHERE", options: .caseInsensitive) {
493
495
  let index: Int = sql
@@ -515,6 +517,8 @@ class UtilsSQLCipher {
515
517
  throw UtilsSQLCipherError.deleteSQL(message: message)
516
518
  } catch UtilsJsonError.isLastModified(let message) {
517
519
  throw UtilsSQLCipherError.deleteSQL(message: message)
520
+ } catch UtilsJsonError.isSqlDeleted(let message) {
521
+ throw UtilsSQLCipherError.deleteSQL(message: message)
518
522
  }
519
523
  }
520
524
 
@@ -13,7 +13,8 @@ enum UtilsSecretError: Error {
13
13
  case setPassphrase(message: String)
14
14
  case changePassphrase(message: String)
15
15
  case setEncryptionSecret(message: String)
16
- case changeEncryptionSecret(message: String)
16
+ case changeEncryptionSecret(message: String)
17
+ case clearEncryptionSecret(message: String)
17
18
  }
18
19
 
19
20
  let oldAccount: String = "CapacitorSQLitePlugin"
@@ -240,4 +241,22 @@ class UtilsSecret {
240
241
  }
241
242
  // swiftlint:enable function_body_length
242
243
 
244
+ // MARK: - ClearEncryptionSecret
245
+
246
+ class func clearEncryptionSecret(prefix: String, databaseLocation: String) throws {
247
+ do {
248
+ if prefix.isEmpty {
249
+ let msg: String = "keychain prefix must not be empty"
250
+ throw UtilsSecretError.setEncryptionSecret(message: msg)
251
+ }
252
+ // clear encrypted passphrase
253
+ let account = "\(prefix)_\(oldAccount)"
254
+ if !getPassphrase(account: account).isEmpty {
255
+ try setPassphrase(account: account, passphrase: "")
256
+ }
257
+ } catch UtilsSecretError.setPassphrase(let message) {
258
+ throw UtilsSecretError.clearEncryptionSecret(message: message)
259
+ }
260
+
261
+ }
243
262
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -55,16 +55,16 @@
55
55
  "prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
56
56
  },
57
57
  "devDependencies": {
58
- "@capacitor/android": "^3.5.0",
59
- "@capacitor/core": "^3.5.0",
58
+ "@capacitor/android": "^3.5.1",
59
+ "@capacitor/core": "^3.5.1",
60
60
  "@capacitor/docgen": "^0.0.17",
61
- "@capacitor/ios": "^3.5.0",
61
+ "@capacitor/ios": "^3.5.1",
62
62
  "@ionic/eslint-config": "^0.3.0",
63
63
  "@ionic/prettier-config": "^1.0.1",
64
64
  "@ionic/swiftlint-config": "^1.1.2",
65
65
  "@rollup/plugin-commonjs": "^20.0.0",
66
66
  "@rollup/plugin-node-resolve": "^13.0.4",
67
- "electron": "^14.2.4",
67
+ "electron": "^15.5.5",
68
68
  "eslint": "^7.11.0",
69
69
  "prettier": "~2.2.0",
70
70
  "prettier-plugin-java": "~1.0.0",
@@ -93,6 +93,6 @@
93
93
  }
94
94
  },
95
95
  "dependencies": {
96
- "jeep-sqlite": "^1.5.1"
96
+ "jeep-sqlite": "^1.5.2"
97
97
  }
98
98
  }