@capacitor-community/sqlite 4.1.0-6 → 4.1.0-8

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.
@@ -162,6 +162,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
162
162
  retHandler.rResult(call: call, message: msg)
163
163
  return
164
164
  }
165
+ let readOnly: Bool = call.getBool("readonly") ?? false
166
+
165
167
  var upgDict: [Int: [String: Any]] = [:]
166
168
  if let cUpgDict = versionUpgrades[dbName] {
167
169
  upgDict = cUpgDict
@@ -171,7 +173,8 @@ public class CapacitorSQLitePlugin: CAPPlugin {
171
173
  encrypted: encrypted,
172
174
  mode: inMode,
173
175
  version: version,
174
- vUpgDict: upgDict)
176
+ vUpgDict: upgDict,
177
+ readonly: readOnly)
175
178
  retHandler.rResult(call: call)
176
179
  return
177
180
  } catch CapacitorSQLiteError.failed(let message) {
@@ -195,8 +198,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
195
198
  message: "Open: Must provide a database name")
196
199
  return
197
200
  }
201
+ let readOnly: Bool = call.getBool("readonly") ?? false
198
202
  do {
199
- try implementation?.open(dbName)
203
+ try implementation?.open(dbName, readonly: readOnly)
200
204
  retHandler.rResult(call: call)
201
205
  return
202
206
  } catch CapacitorSQLiteError.failed(let message) {
@@ -220,8 +224,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
220
224
  message: "Close: Must provide a database name")
221
225
  return
222
226
  }
227
+ let readOnly: Bool = call.getBool("readonly") ?? false
223
228
  do {
224
- try implementation?.close(dbName)
229
+ try implementation?.close(dbName, readonly: readOnly)
225
230
  retHandler.rResult(call: call)
226
231
  return
227
232
  } catch CapacitorSQLiteError.failed(let message) {
@@ -245,8 +250,11 @@ public class CapacitorSQLitePlugin: CAPPlugin {
245
250
  message: "GetUrl: Must provide a database name")
246
251
  return
247
252
  }
253
+ let readOnly: Bool = call.getBool("readonly") ?? false
248
254
  do {
249
- let res: String = try implementation?.getUrl(dbName) ?? ""
255
+ let res: String = try implementation?.getUrl(dbName,
256
+ readonly: readOnly) ?? ""
257
+
250
258
  if res.count > 0 {
251
259
  retHandler.rUrl(call: call, ret: res)
252
260
  return
@@ -278,9 +286,10 @@ public class CapacitorSQLitePlugin: CAPPlugin {
278
286
  message: "getVersion: Must provide a database name")
279
287
  return
280
288
  }
289
+ let readOnly: Bool = call.getBool("readonly") ?? false
281
290
  do {
282
291
  if let version: NSNumber = try implementation?
283
- .getVersion(dbName) {
292
+ .getVersion(dbName, readonly: readOnly) {
284
293
  retHandler.rVersion(call: call, ret: version)
285
294
  return
286
295
  } else {
@@ -309,8 +318,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
309
318
  message: "CloseConnection: Must provide a database name")
310
319
  return
311
320
  }
321
+ let readOnly: Bool = call.getBool("readonly") ?? false
312
322
  do {
313
- try implementation?.closeConnection(dbName)
323
+ try implementation?.closeConnection(dbName, readonly: readOnly)
314
324
  retHandler.rResult(call: call)
315
325
  return
316
326
  } catch CapacitorSQLiteError.failed(let message) {
@@ -396,8 +406,11 @@ public class CapacitorSQLitePlugin: CAPPlugin {
396
406
  message: "IsTableExists: Must provide a table name")
397
407
  return
398
408
  }
409
+ let readOnly: Bool = call.getBool("readonly") ?? false
399
410
  do {
400
- let res = try implementation?.isTableExists(dbName, tableName: tableName)
411
+ let res = try implementation?.isTableExists(dbName,
412
+ tableName: tableName,
413
+ readonly: readOnly)
401
414
  var bRes: Bool = false
402
415
  if res == 1 {
403
416
  bRes = true
@@ -425,8 +438,10 @@ public class CapacitorSQLitePlugin: CAPPlugin {
425
438
  return
426
439
 
427
440
  }
441
+ let readOnly: Bool = call.getBool("readonly") ?? false
428
442
  do {
429
- let res = try implementation?.getTableList(dbName) ?? []
443
+ let res = try implementation?.getTableList(dbName,
444
+ readonly: readOnly) ?? []
430
445
  retHandler.rValues(call: call, ret: res)
431
446
  return
432
447
  } catch CapacitorSQLiteError.failed(let message) {
@@ -597,10 +612,11 @@ public class CapacitorSQLitePlugin: CAPPlugin {
597
612
  message: msg)
598
613
  return
599
614
  }
615
+ let readOnly: Bool = call.getBool("readonly") ?? false
600
616
  do {
601
617
  if let res = try implementation?
602
618
  .execute(dbName, statements: statements,
603
- transaction: transaction) {
619
+ transaction: transaction, readonly: readOnly) {
604
620
  retHandler.rChanges(call: call, ret: res)
605
621
  return
606
622
  } else {
@@ -660,9 +676,11 @@ public class CapacitorSQLitePlugin: CAPPlugin {
660
676
  }
661
677
  }
662
678
  let transaction: Bool = call.getBool("transaction") ?? true
679
+ let readOnly: Bool = call.getBool("readonly") ?? false
663
680
  do {
664
681
  if let res = try implementation?.executeSet(dbName, set: set,
665
- transaction: transaction) {
682
+ transaction: transaction,
683
+ readonly: readOnly) {
666
684
  retHandler.rChanges(call: call, ret: res)
667
685
  return
668
686
  } else {
@@ -714,12 +732,14 @@ public class CapacitorSQLitePlugin: CAPPlugin {
714
732
  return
715
733
  }
716
734
  let transaction: Bool = call.getBool("transaction") ?? true
735
+ let readOnly: Bool = call.getBool("readonly") ?? false
717
736
  do {
718
737
  if let res = try
719
738
  implementation?.run(dbName,
720
739
  statement: statement,
721
740
  values: values,
722
- transaction: transaction) {
741
+ transaction: transaction,
742
+ readonly: readOnly) {
723
743
  retHandler.rChanges(call: call, ret: res)
724
744
  return
725
745
  } else {
@@ -772,11 +792,13 @@ public class CapacitorSQLitePlugin: CAPPlugin {
772
792
  return
773
793
 
774
794
  }
795
+ let readOnly: Bool = call.getBool("readonly") ?? false
775
796
  do {
776
797
  if let res: [[String: Any]] = try
777
798
  implementation?.query(dbName,
778
799
  statement: statement,
779
- values: values) {
800
+ values: values,
801
+ readonly: readOnly) {
780
802
  retHandler.rValues(call: call, ret: res)
781
803
  return
782
804
  } else {
@@ -811,8 +833,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
811
833
  message: "isDBExists: Must provide a database name")
812
834
  return
813
835
  }
836
+ let readOnly: Bool = call.getBool("readonly") ?? false
814
837
  do {
815
- let res = try implementation?.isDBExists(dbName)
838
+ let res = try implementation?.isDBExists(dbName, readonly: readOnly)
816
839
  var bRes: Bool = false
817
840
  if res == 1 {
818
841
  bRes = true
@@ -841,8 +864,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
841
864
  message: "idDBOpen: Must provide a database name")
842
865
  return
843
866
  }
867
+ let readOnly: Bool = call.getBool("readonly") ?? false
844
868
  do {
845
- let res = try implementation?.isDBOpen(dbName)
869
+ let res = try implementation?.isDBOpen(dbName, readonly: readOnly)
846
870
  var bRes: Bool = false
847
871
  if res == 1 {
848
872
  bRes = true
@@ -870,8 +894,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
870
894
  retHandler.rResult(call: call, message: msg)
871
895
  return
872
896
  }
897
+ let readOnly: Bool = call.getBool("readonly") ?? false
873
898
  do {
874
- try implementation?.deleteDatabase(dbName)
899
+ try implementation?.deleteDatabase(dbName, readonly: readOnly)
875
900
  retHandler.rResult(call: call)
876
901
  return
877
902
  } catch CapacitorSQLiteError.failed(let message) {
@@ -966,10 +991,12 @@ public class CapacitorSQLitePlugin: CAPPlugin {
966
991
  message: msg)
967
992
  return
968
993
  }
994
+ let readOnly: Bool = call.getBool("readonly") ?? false
969
995
 
970
996
  do {
971
997
  let res: [String: Any] = try implementation?
972
- .exportToJson(dbName, expMode: expMode) ?? [:]
998
+ .exportToJson(dbName, expMode: expMode,
999
+ readonly: readOnly) ?? [:]
973
1000
  retHandler.rJsonSQLite(call: call, ret: res)
974
1001
  return
975
1002
  } catch CapacitorSQLiteError.failed(let message) {
@@ -995,8 +1022,9 @@ public class CapacitorSQLitePlugin: CAPPlugin {
995
1022
  retHandler.rResult(call: call, message: msg)
996
1023
  return
997
1024
  }
1025
+ let readOnly: Bool = call.getBool("readonly") ?? false
998
1026
  do {
999
- try implementation?.deleteExportedRows(dbName)
1027
+ try implementation?.deleteExportedRows(dbName, readonly: readOnly)
1000
1028
  retHandler.rResult(call: call)
1001
1029
  return
1002
1030
  } catch CapacitorSQLiteError.failed(let message) {
@@ -1021,9 +1049,10 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1021
1049
  "Must provide a database name")
1022
1050
  return
1023
1051
  }
1052
+ let readOnly: Bool = call.getBool("readonly") ?? false
1024
1053
  do {
1025
1054
  let res: NSNumber = try implementation?
1026
- .createSyncTable(dbName) ?? -1
1055
+ .createSyncTable(dbName, readonly: readOnly) ?? -1
1027
1056
  retHandler.rChanges(call: call,
1028
1057
  ret: ["changes": Int(truncating: res)])
1029
1058
  return
@@ -1056,8 +1085,10 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1056
1085
  retHandler.rResult(call: call, message: msg)
1057
1086
  return
1058
1087
  }
1088
+ let readOnly: Bool = call.getBool("readonly") ?? false
1059
1089
  do {
1060
- try implementation?.setSyncDate( dbName, syncDate: syncDate)
1090
+ try implementation?.setSyncDate( dbName, syncDate: syncDate,
1091
+ readonly: readOnly)
1061
1092
  retHandler.rResult(call: call)
1062
1093
  return
1063
1094
  } catch CapacitorSQLiteError.failed(let message) {
@@ -1080,8 +1111,10 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1080
1111
  retHandler.rSyncDate(call: call, ret: 0, message: msg)
1081
1112
  return
1082
1113
  }
1114
+ let readOnly: Bool = call.getBool("readonly") ?? false
1083
1115
  do {
1084
- let res: NSNumber = try implementation?.getSyncDate( dbName) ?? 0
1116
+ let res: NSNumber = try implementation?
1117
+ .getSyncDate( dbName, readonly: readOnly) ?? 0
1085
1118
  retHandler.rSyncDate(call: call,
1086
1119
  ret: Int64(truncating: res))
1087
1120
  return
@@ -46,9 +46,11 @@ class Database {
46
46
  var ncDB: Bool = false
47
47
 
48
48
  // MARK: - Init
49
- init(databaseLocation: String, databaseName: String, encrypted: Bool,
50
- isEncryption: Bool, account: String, mode: String, version: Int,
51
- vUpgDict: [Int: [String: Any]] = [:]) throws {
49
+ init(databaseLocation: String, databaseName: String,
50
+ encrypted: Bool, isEncryption: Bool,
51
+ account: String, mode: String, version: Int, readonly: Bool,
52
+ vUpgDict: [Int: [String: Any]] = [:]
53
+ ) throws {
52
54
  self.dbVersion = version
53
55
  self.encrypted = encrypted
54
56
  self.isEncryption = isEncryption
@@ -57,6 +59,7 @@ class Database {
57
59
  self.mode = mode
58
60
  self.vUpgDict = vUpgDict
59
61
  self.databaseLocation = databaseLocation
62
+ self.readOnly = readonly
60
63
  if databaseName.contains("/") &&
61
64
  databaseName.suffix(9) != "SQLite.db" {
62
65
  self.readOnly = true
@@ -133,7 +136,7 @@ class Database {
133
136
  try UtilsSQLCipher
134
137
  .setForeignKeyConstraintsEnabled(mDB: self,
135
138
  toggle: true)
136
- if !ncDB {
139
+ if !ncDB && !self.readOnly {
137
140
  let curVersion: Int = try UtilsSQLCipher.getVersion(mDB: self)
138
141
 
139
142
  if dbVersion > curVersion && vUpgDict.count > 0 {
@@ -14,31 +14,26 @@ enum UtilsUpgradeError: Error {
14
14
  case updateDatabaseVersionFailed(message: String)
15
15
  case executeStatementsProcessFailed(message: String)
16
16
  }
17
- // swiftlint:disable file_length
18
- // swiftlint:disable type_body_length
19
17
  class UtilsUpgrade {
20
18
  // MARK: - onUpgrade
21
-
22
- // swiftlint:disable cyclomatic_complexity
23
- // swiftlint:disable function_body_length
24
- // swiftlint:disable function_parameter_count
19
+
25
20
  func onUpgrade(mDB: Database,
26
21
  upgDict: [Int: [String: Any]],
27
22
  currentVersion: Int,
28
23
  targetVersion: Int,
29
24
  databaseLocation: String) throws {
30
25
  print("UtilsUpgrade.onUpgrade: \(currentVersion) => \(targetVersion)")
31
-
26
+
32
27
  for (versionKey, upgrade) in Array(upgDict).sorted(by: {$0.0 < $1.0}) {
33
- if (versionKey > currentVersion && versionKey <= targetVersion) {
28
+ if versionKey > currentVersion && versionKey <= targetVersion {
34
29
  guard let statements = upgrade["statements"] as? [String] else {
35
30
  let msg: String = "Error: onUpgrade statements not given"
36
31
  throw UtilsUpgradeError.onUpgradeFailed(message: msg)
37
32
  }
38
-
33
+
39
34
  do {
40
35
  _ = try executeStatementsProcess(mDB: mDB, statements: statements)
41
-
36
+
42
37
  try UtilsSQLCipher.setVersion(mDB: mDB, version: versionKey)
43
38
  } catch UtilsSQLCipherError.setVersion(let message) {
44
39
  throw UtilsUpgradeError.onUpgradeFailed(message: "Error: onUpgrade update version: \(message)")
@@ -48,12 +43,9 @@ class UtilsUpgrade {
48
43
  }
49
44
  }
50
45
  }
51
- // swiftlint:enable function_parameter_count
52
- // swiftlint:enable function_body_length
53
- // swiftlint:enable cyclomatic_complexity
54
-
46
+
55
47
  // MARK: - ExecuteStatementProcess
56
-
48
+
57
49
  func executeStatementsProcess(mDB: Database, statements: [String])
58
50
  throws {
59
51
  do {
@@ -62,29 +54,28 @@ class UtilsUpgrade {
62
54
  } catch UtilsSQLCipherError.beginTransaction(let message) {
63
55
  throw DatabaseError.executeSQL(message: "Error: onUpgrade: \(message)")
64
56
  }
65
-
57
+
66
58
  // -> Excecute statements
67
- for (statement) in statements{
59
+ for (statement) in statements {
68
60
  _ = try mDB.executeSQL(sql: statement, transaction: false)
69
61
  }
70
-
62
+
71
63
  do {
72
64
  try UtilsSQLCipher.commitTransaction(mDB: mDB)
73
65
  } catch UtilsSQLCipherError.commitTransaction(let message) {
74
66
  throw DatabaseError.executeSQL(message: "Error: onUpgrade: \(message)")
75
67
  }
76
-
68
+
77
69
  } catch DatabaseError.executeSQL(let message) {
78
70
  do {
79
71
  try UtilsSQLCipher.rollbackTransaction(mDB: mDB)
80
72
  } catch UtilsSQLCipherError.rollbackTransaction(let message2) {
81
73
  throw DatabaseError.executeSQL(message: "Error: onUpgrade: \(message) \(message2)")
82
74
  }
83
-
75
+
84
76
  throw UtilsUpgradeError.executeStatementsProcessFailed(message: message)
85
77
  }
86
-
78
+
87
79
  }
88
80
  }
89
81
  // swiftlint:enable type_body_length
90
- // swiftlint:enable file_length
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "4.1.0-6",
3
+ "version": "4.1.0-8",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",