@capacitor-community/sqlite 5.0.5-2 → 5.0.6

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 (44) hide show
  1. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +118 -156
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +81 -249
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/NotificationCenter.java +1 -1
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +0 -12
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +184 -40
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +141 -135
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +2 -1
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsEncryption.java +111 -0
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java +0 -4
  10. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +30 -18
  11. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +12 -4
  12. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsNCDatabase.java +4 -1
  13. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java +8 -6
  14. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLite.java +14 -28
  15. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSecret.java +3 -4
  16. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +0 -1
  17. package/dist/esm/definitions.d.ts +91 -4
  18. package/dist/esm/definitions.js +79 -19
  19. package/dist/esm/definitions.js.map +1 -1
  20. package/dist/esm/web.d.ts +3 -1
  21. package/dist/esm/web.js +8 -0
  22. package/dist/esm/web.js.map +1 -1
  23. package/dist/plugin.cjs.js +87 -19
  24. package/dist/plugin.cjs.js.map +1 -1
  25. package/dist/plugin.js +87 -19
  26. package/dist/plugin.js.map +1 -1
  27. package/electron/dist/plugin.js +333 -148
  28. package/electron/dist/plugin.js.map +1 -1
  29. package/electron/rollup.config.js +2 -0
  30. package/ios/Plugin/CapacitorSQLite.swift +125 -92
  31. package/ios/Plugin/CapacitorSQLitePlugin.swift +6 -3
  32. package/ios/Plugin/Database.swift +45 -19
  33. package/ios/Plugin/ImportExportJson/ExportToJson.swift +10 -5
  34. package/ios/Plugin/ImportExportJson/ImportData.swift +434 -0
  35. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +47 -59
  36. package/ios/Plugin/ImportExportJson/JsonSQLite.swift +7 -0
  37. package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +61 -61
  38. package/ios/Plugin/Utils/UtilsDrop.swift +2 -1
  39. package/ios/Plugin/Utils/UtilsJson.swift +123 -1
  40. package/ios/Plugin/Utils/UtilsSQLCipher.swift +254 -23
  41. package/ios/Plugin/Utils/UtilsUpgrade.swift +0 -1
  42. package/package.json +2 -2
  43. package/src/definitions.ts +171 -18
  44. package/src/web.ts +10 -0
@@ -17,6 +17,8 @@ export default {
17
17
  'electron',
18
18
  'electron-json-storage',
19
19
  'better-sqlite3-multiple-ciphers',
20
+ 'crypto',
21
+ 'crypto-js',
20
22
  'path',
21
23
  'fs',
22
24
  'os',
@@ -735,7 +735,7 @@ enum CapacitorSQLiteError: Error {
735
735
  // MARK: - ExecuteSet
736
736
 
737
737
  @objc func executeSet(_ dbName: String, set: [[String: Any]],
738
- transaction: Bool, readonly: Bool)
738
+ transaction: Bool, readonly: Bool, returnMode: String)
739
739
  throws -> [String: Any] {
740
740
  if isInit {
741
741
  let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
@@ -750,7 +750,8 @@ enum CapacitorSQLiteError: Error {
750
750
  }
751
751
  if !mDb.isNCDB() && mDb.isDBOpen() {
752
752
  do {
753
- let res = try mDb.execSet(set: set, transaction: transaction)
753
+ let res = try mDb.execSet(set: set, transaction: transaction,
754
+ returnMode: returnMode)
754
755
  return res
755
756
  } catch DatabaseError.execSet(let message) {
756
757
  throw CapacitorSQLiteError.failed(message: message)
@@ -771,8 +772,9 @@ enum CapacitorSQLiteError: Error {
771
772
 
772
773
  // swiftlint:disable function_body_length
773
774
  // swiftlint:disable cyclomatic_complexity
775
+ // swiftlint:disable function_parameter_count
774
776
  @objc func run(_ dbName: String, statement: String, values: [Any],
775
- transaction: Bool, readonly: Bool)
777
+ transaction: Bool, readonly: Bool, returnMode: String)
776
778
  throws -> [String: Any] {
777
779
  if isInit {
778
780
  let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
@@ -834,7 +836,8 @@ enum CapacitorSQLiteError: Error {
834
836
  }
835
837
  }
836
838
  let res = try mDb.runSQL(sql: statement, values: val,
837
- transaction: transaction)
839
+ transaction: transaction,
840
+ returnMode: returnMode)
838
841
  return res
839
842
  } catch DatabaseError.runSQL(let message) {
840
843
  throw CapacitorSQLiteError.failed(message: message)
@@ -850,6 +853,7 @@ enum CapacitorSQLiteError: Error {
850
853
  throw CapacitorSQLiteError.failed(message: initMessage)
851
854
  }
852
855
  }
856
+ // swiftlint:enable function_parameter_count
853
857
  // swiftlint:enable cyclomatic_complexity
854
858
  // swiftlint:enable function_body_length
855
859
 
@@ -1018,112 +1022,140 @@ enum CapacitorSQLiteError: Error {
1018
1022
  throws -> [String: Int] {
1019
1023
  if isInit {
1020
1024
  var mDb: Database
1021
- if let data = ("["+parsingData+"]").data(using: .utf8) {
1025
+ var importData: ImportData
1026
+ // check if json object is encrypted
1027
+ if parsingData.contains("expData") {
1028
+ guard let data = ("["+parsingData+"]")
1029
+ .data(using: .utf8) else {
1030
+ let msg: String = "Stringify Encrypted Json Object " +
1031
+ "not Valid"
1032
+ throw CapacitorSQLiteError.failed(message: msg)
1033
+ }
1034
+ var encryptJson: [EncryptJson]
1035
+ do {
1036
+ encryptJson = try JSONDecoder()
1037
+ .decode([EncryptJson].self, from: data)
1038
+ let dict: [String: Any] = try
1039
+ UtilsJson.decryptBase64ToDictionary(
1040
+ encryptJson[0].expData,
1041
+ forAccount: account)
1042
+ importData = ImportData(jsonDict: dict)
1043
+ } catch let error {
1044
+ var msg: String = "Encrypted Json Object not Valid "
1045
+ msg.append("\(error)")
1046
+ throw CapacitorSQLiteError.failed(message: msg)
1047
+ }
1048
+
1049
+ } else {
1050
+
1051
+ guard let data = ("["+parsingData+"]")
1052
+ .data(using: .utf8) else {
1053
+ let msg: String = "Stringify Json Object not Valid"
1054
+ throw CapacitorSQLiteError.failed(message: msg)
1055
+ }
1022
1056
  var jsonSQLite: [JsonSQLite]
1023
1057
  do {
1024
1058
  jsonSQLite = try JSONDecoder()
1025
1059
  .decode([JsonSQLite].self, from: data)
1060
+ importData = ImportData(jsonSQLite: jsonSQLite[0])
1061
+ jsonSQLite = []
1026
1062
  } catch let error {
1027
1063
  var msg: String = "Stringify Json Object not Valid "
1028
1064
  msg.append("\(error)")
1029
1065
  throw CapacitorSQLiteError.failed(message: msg)
1030
1066
  }
1031
- let encrypted: Bool = jsonSQLite[0].encrypted
1032
- var overwrite: Bool = false
1033
- if let mOverwrite = jsonSQLite[0].overwrite {
1034
- overwrite = mOverwrite
1035
- }
1036
- let mode: String = jsonSQLite[0].mode
1037
- let inMode: String = encrypted ? "secret"
1038
- : "no-encryption"
1039
- let version: Int = jsonSQLite[0].version
1040
- var dbName: String = CapacitorSQLite.getDatabaseName(
1041
- dbName: jsonSQLite[0].database
1042
- )
1043
- dbName.append("SQLite.db")
1044
- // open the database
1045
- do {
1046
- mDb = try Database(
1047
- databaseLocation: databaseLocation, databaseName: dbName,
1048
- encrypted: encrypted, isEncryption: isEncryption,
1049
- account: account,
1050
- mode: inMode, version: version, readonly: false,
1051
- vUpgDict: [:])
1052
- if overwrite && mode == "full" {
1053
- let isExists = UtilsFile
1054
- .isFileExist(databaseLocation: databaseLocation,
1055
- fileName: dbName)
1056
- if isExists {
1057
- _ = try UtilsFile
1058
- .deleteFile(fileName: dbName,
1059
- databaseLocation: databaseLocation)
1060
- }
1067
+
1068
+ }
1069
+ let encrypted: Bool = importData.encrypted
1070
+ let overwrite: Bool = importData.overwrite ?
1071
+ importData.overwrite : false
1072
+ let mode: String = importData.mode
1073
+ let inMode: String = encrypted ? "secret"
1074
+ : "no-encryption"
1075
+ let version: Int = importData.version
1076
+ var dbName: String = CapacitorSQLite.getDatabaseName(
1077
+ dbName: importData.database
1078
+ )
1079
+ dbName.append("SQLite.db")
1080
+ // open the database
1081
+ do {
1082
+ mDb = try Database(
1083
+ databaseLocation: databaseLocation, databaseName: dbName,
1084
+ encrypted: encrypted, isEncryption: isEncryption,
1085
+ account: account,
1086
+ mode: inMode, version: version, readonly: false,
1087
+ vUpgDict: [:])
1088
+ if overwrite && mode == "full" {
1089
+ let isExists = UtilsFile
1090
+ .isFileExist(databaseLocation: databaseLocation,
1091
+ fileName: dbName)
1092
+ if isExists {
1093
+ _ = try UtilsFile
1094
+ .deleteFile(fileName: dbName,
1095
+ databaseLocation: databaseLocation)
1061
1096
  }
1062
- try mDb.open()
1063
- } catch UtilsFileError.deleteFileFailed {
1064
- let message = "Delete Database failed"
1065
- throw CapacitorSQLiteError.failed(message: message)
1066
- } catch DatabaseError.open(let message) {
1067
- throw CapacitorSQLiteError.failed(message: message)
1068
- } catch let error {
1069
- let msg: String = "\(error)"
1070
- throw CapacitorSQLiteError.failed(message: msg)
1071
1097
  }
1072
- // check if the database as some tables
1073
- do {
1074
- let tableList: [String] = try mDb.getTableNames()
1075
- if mode == "full" && tableList.count > 0 {
1076
- let curVersion = try mDb.getVersion()
1077
- if version < curVersion {
1078
- var msg: String = "ImportFromJson: Cannot import a "
1079
- msg += "version lower than \(curVersion)"
1080
- throw CapacitorSQLiteError.failed(message: msg)
1081
- }
1082
- if curVersion == version {
1083
- var res: [String: Int] = [:]
1084
- res["changes"] = 0
1085
- return res
1086
- }
1098
+ try mDb.open()
1099
+ } catch UtilsFileError.deleteFileFailed {
1100
+ let message = "Delete Database failed"
1101
+ throw CapacitorSQLiteError.failed(message: message)
1102
+ } catch DatabaseError.open(let message) {
1103
+ throw CapacitorSQLiteError.failed(message: message)
1104
+ } catch let error {
1105
+ let msg: String = "\(error)"
1106
+ throw CapacitorSQLiteError.failed(message: msg)
1107
+ }
1108
+ // check if the database as some tables
1109
+ do {
1110
+ let tableList: [String] = try mDb.getTableNames()
1111
+ if mode == "full" && tableList.count > 0 {
1112
+ let curVersion = try mDb.getVersion()
1113
+ if version < curVersion {
1114
+ var msg: String = "ImportFromJson: Cannot import a "
1115
+ msg += "version lower than \(curVersion)"
1116
+ throw CapacitorSQLiteError.failed(message: msg)
1087
1117
  }
1118
+ if curVersion == version {
1119
+ var res: [String: Int] = [:]
1120
+ res["changes"] = 0
1121
+ return res
1122
+ }
1123
+ }
1088
1124
 
1089
- } catch DatabaseError.getTableNames(let message) {
1090
- throw CapacitorSQLiteError.failed(message: message)
1091
- } catch let error {
1092
- let msg: String = "\(error)"
1125
+ } catch DatabaseError.getTableNames(let message) {
1126
+ throw CapacitorSQLiteError.failed(message: message)
1127
+ } catch let error {
1128
+ let msg: String = "\(error)"
1129
+ throw CapacitorSQLiteError.failed(message: msg)
1130
+ }
1131
+ // import from Json Object
1132
+ do {
1133
+ let res: [String: Int] = try mDb
1134
+ .importFromJson(importData: importData)
1135
+ try mDb.close()
1136
+ if let result = res["changes"] {
1137
+ if result < 0 {
1138
+ let msg: String = "changes < 0"
1139
+ throw CapacitorSQLiteError
1140
+ .failed(message: msg)
1141
+ } else {
1142
+ return res
1143
+ }
1144
+ } else {
1145
+ let msg: String = "changes not found"
1093
1146
  throw CapacitorSQLiteError.failed(message: msg)
1094
1147
  }
1095
- // import from Json Object
1148
+ } catch DatabaseError.importFromJson(let message) {
1149
+ var msg = message
1096
1150
  do {
1097
- let res: [String: Int] = try mDb
1098
- .importFromJson(jsonSQLite: jsonSQLite[0])
1099
1151
  try mDb.close()
1100
- if let result = res["changes"] {
1101
- if result < 0 {
1102
- let msg: String = "changes < 0"
1103
- throw CapacitorSQLiteError
1104
- .failed(message: msg)
1105
- } else {
1106
- return res
1107
- }
1108
- } else {
1109
- let msg: String = "changes not found"
1110
- throw CapacitorSQLiteError.failed(message: msg)
1111
- }
1112
- } catch DatabaseError.importFromJson(let message) {
1113
- var msg = message
1114
- do {
1115
- try mDb.close()
1116
- throw CapacitorSQLiteError.failed(message: msg)
1117
- } catch DatabaseError.close(let message) {
1118
- msg.append(" \(message)")
1119
- throw CapacitorSQLiteError.failed(message: msg)
1120
- }
1152
+ throw CapacitorSQLiteError.failed(message: msg)
1121
1153
  } catch DatabaseError.close(let message) {
1122
- throw CapacitorSQLiteError.failed(message: message)
1154
+ msg.append(" \(message)")
1155
+ throw CapacitorSQLiteError.failed(message: msg)
1123
1156
  }
1124
- } else {
1125
- let msg: String = "Stringify Json Object not Valid"
1126
- throw CapacitorSQLiteError.failed(message: msg)
1157
+ } catch DatabaseError.close(let message) {
1158
+ throw CapacitorSQLiteError.failed(message: message)
1127
1159
  }
1128
1160
  } else {
1129
1161
  throw CapacitorSQLiteError.failed(message: initMessage)
@@ -1152,7 +1184,8 @@ enum CapacitorSQLiteError: Error {
1152
1184
  var msg: String = "return Object is empty "
1153
1185
  msg.append("No data to synchronize")
1154
1186
  throw CapacitorSQLiteError.failed(message: msg)
1155
-
1187
+ } else if res.count == 1 && res.contains(where: { $0.key == "expData" }) {
1188
+ return res
1156
1189
  } else if res.count == 5 || res.count == 6 ||
1157
1190
  res.count == 7 {
1158
1191
  return res
@@ -767,10 +767,12 @@ public class CapacitorSQLitePlugin: CAPPlugin {
767
767
  }
768
768
  let transaction: Bool = call.getBool("transaction") ?? true
769
769
  let readOnly: Bool = call.getBool("readonly") ?? false
770
+ let returnMode: String = call.getString("returnMode") ?? "no"
770
771
  do {
771
772
  if let res = try implementation?.executeSet(dbName, set: set,
772
773
  transaction: transaction,
773
- readonly: readOnly) {
774
+ readonly: readOnly,
775
+ returnMode: returnMode) {
774
776
  retHandler.rChanges(call: call, ret: res)
775
777
  return
776
778
  } else {
@@ -823,13 +825,15 @@ public class CapacitorSQLitePlugin: CAPPlugin {
823
825
  }
824
826
  let transaction: Bool = call.getBool("transaction") ?? true
825
827
  let readOnly: Bool = call.getBool("readonly") ?? false
828
+ let returnMode: String = call.getString("returnMode") ?? "no"
826
829
  do {
827
830
  if let res = try
828
831
  implementation?.run(dbName,
829
832
  statement: statement,
830
833
  values: values,
831
834
  transaction: transaction,
832
- readonly: readOnly) {
835
+ readonly: readOnly,
836
+ returnMode: returnMode) {
833
837
  retHandler.rChanges(call: call, ret: res)
834
838
  return
835
839
  } else {
@@ -1414,7 +1418,6 @@ public class CapacitorSQLitePlugin: CAPPlugin {
1414
1418
  return
1415
1419
  }
1416
1420
  DispatchQueue.global(qos: .background).async {
1417
-
1418
1421
  do {
1419
1422
  try self.implementation?.getFromHTTPRequest(call, url: url)
1420
1423
  DispatchQueue.main.async {
@@ -297,13 +297,17 @@ class Database {
297
297
 
298
298
  // MARK: - ExecSet
299
299
 
300
- func execSet(set: [[String: Any]], transaction: Bool = true) throws -> [String: Int64] {
300
+ // swiftlint:disable function_body_length
301
+ func execSet(set: [[String: Any]], transaction: Bool = true,
302
+ returnMode: String = "no") throws -> [String: Any] {
301
303
  var msg: String = "Failed in execSet : "
302
304
  let initChanges = UtilsSQLCipher.dbChanges(mDB: mDb)
303
305
  var changes: Int = -1
304
306
  var lastId: Int64 = -1
305
- var changesDict: [String: Int64] = ["lastId": lastId,
306
- "changes": Int64(changes)]
307
+ var response: [[String: Any]] = []
308
+ var changesDict: [String: Any] = ["lastId": lastId,
309
+ "changes": changes,
310
+ "values": [[:]]]
307
311
 
308
312
  // Start a transaction
309
313
  if transaction {
@@ -316,12 +320,15 @@ class Database {
316
320
  }
317
321
  // Execute the query
318
322
  do {
319
- lastId = try UtilsSQLCipher
320
- .executeSet(mDB: self, set: set)
323
+ let resp = try UtilsSQLCipher
324
+ .executeSet(mDB: self, set: set, returnMode: returnMode)
325
+ lastId = resp.0
326
+ response = resp.1
321
327
  changes = UtilsSQLCipher
322
328
  .dbChanges(mDB: mDb) - initChanges
323
- changesDict["changes"] = Int64(changes)
329
+ changesDict["changes"] = changes
324
330
  changesDict["lastId"] = lastId
331
+ changesDict["values"] = response
325
332
 
326
333
  } catch UtilsSQLCipherError
327
334
  .executeSet(let message) {
@@ -352,12 +359,13 @@ class Database {
352
359
 
353
360
  // MARK: - RunSQL
354
361
 
355
- func runSQL(sql: String, values: [Any], transaction: Bool = true) throws -> [String: Int64] {
362
+ func runSQL(sql: String, values: [Any], transaction: Bool = true,
363
+ returnMode: String = "no") throws -> [String: Any] {
356
364
  var msg: String = "Failed in runSQL : "
357
365
  var changes: Int = -1
358
366
  var lastId: Int64 = -1
367
+ var response: [[String: Any]] = []
359
368
  let initChanges = UtilsSQLCipher.dbChanges(mDB: mDb)
360
-
361
369
  // Start a transaction
362
370
  if transaction {
363
371
  do {
@@ -370,9 +378,11 @@ class Database {
370
378
  }
371
379
  // Execute the query
372
380
  do {
373
- lastId = try UtilsSQLCipher
381
+ let resp = try UtilsSQLCipher
374
382
  .prepareSQL(mDB: self, sql: sql, values: values,
375
- fromJson: false)
383
+ fromJson: false, returnMode: returnMode)
384
+ lastId = resp.0
385
+ response = resp.1
376
386
  } catch UtilsSQLCipherError.prepareSQL(let message) {
377
387
  if transaction {
378
388
  do {
@@ -400,8 +410,9 @@ class Database {
400
410
  }
401
411
  }
402
412
  changes = UtilsSQLCipher.dbChanges(mDB: mDb) - initChanges
403
- let result: [String: Int64] = ["changes": Int64(changes),
404
- "lastId": lastId]
413
+ let result: [String: Any] = ["changes": changes,
414
+ "lastId": lastId,
415
+ "values": response]
405
416
  return result
406
417
  }
407
418
 
@@ -511,6 +522,8 @@ class Database {
511
522
 
512
523
  func setSyncDate(syncDate: String ) throws -> Bool {
513
524
  var retBool: Bool = false
525
+ var lastId: Int64 = -1
526
+ var resp: [String: Any] = [:]
514
527
  do {
515
528
  let isExists: Bool = try UtilsJson.isTableExists(
516
529
  mDB: self, tableName: "sync_table")
@@ -524,8 +537,9 @@ class Database {
524
537
  let syncTime: Int = Int(date.timeIntervalSince1970)
525
538
  var stmt: String = "UPDATE sync_table SET sync_date = "
526
539
  stmt.append("\(syncTime) WHERE id = 1;")
527
- let retRun = try runSQL(sql: stmt, values: [])
528
- if let lastId: Int64 = retRun["lastId"] {
540
+ resp = try runSQL(sql: stmt, values: [])
541
+ if let mLastId: Int64 = resp["lastId"] as? Int64 {
542
+ lastId = mLastId
529
543
  if lastId != -1 {
530
544
  retBool = true
531
545
  }
@@ -580,6 +594,15 @@ class Database {
580
594
  "expMode": expMode, "version": dbVersion]
581
595
  retObj = try ExportToJson
582
596
  .createExportObject(mDB: self, data: data)
597
+ if isEncryption && encrypted {
598
+ retObj["overwrite"] = true
599
+ let base64Str = try UtilsJson.encryptDictionaryToBase64(
600
+ retObj,
601
+ forAccount: account)
602
+ retObj = [:]
603
+ retObj["expData"] = base64Str
604
+ }
605
+
583
606
  } catch UtilsJsonError.tableNotExists(let message) {
584
607
  throw DatabaseError.exportToJson(message: message)
585
608
  } catch ExportToJsonError.setLastExportDate(let message) {
@@ -603,7 +626,7 @@ class Database {
603
626
 
604
627
  // MARK: - ImportFromJson
605
628
 
606
- func importFromJson(jsonSQLite: JsonSQLite)
629
+ func importFromJson(importData: ImportData)
607
630
  throws -> [String: Int] {
608
631
  var changes: Int = 0
609
632
 
@@ -613,18 +636,21 @@ class Database {
613
636
  try UtilsSQLCipher
614
637
  .setForeignKeyConstraintsEnabled(mDB: self,
615
638
  toggle: false)
616
- if jsonSQLite.tables.count > 0 {
639
+ if importData.tables.count > 0 {
617
640
  changes = try ImportFromJson
618
641
  .createDatabaseSchema(mDB: self,
619
- jsonSQLite: jsonSQLite)
642
+ tables: importData.tables,
643
+ mode: importData.mode,
644
+ version: importData.version)
620
645
  if changes != -1 {
621
646
  // Create the Database Data
622
647
  changes += try ImportFromJson
623
648
  .createDatabaseData(mDB: self,
624
- jsonSQLite: jsonSQLite)
649
+ tables: importData.tables,
650
+ mode: importData.mode)
625
651
  }
626
652
  }
627
- if let mViews = jsonSQLite.views {
653
+ if let mViews = importData.views {
628
654
  if mViews.count > 0 {
629
655
  changes += try ImportFromJson
630
656
  .createViews(mDB: self, views: mViews)
@@ -88,6 +88,7 @@ class ExportToJson {
88
88
  // MARK: - ExportToJson - SetLastExportDate
89
89
 
90
90
  class func setLastExportDate(mDB: Database, sTime: Int) throws {
91
+ var lastId: Int64 = -1
91
92
  do {
92
93
  let isExists: Bool = try UtilsJson.isTableExists(
93
94
  mDB: mDB, tableName: "sync_table")
@@ -103,8 +104,10 @@ class ExportToJson {
103
104
  } else {
104
105
  stmt = "INSERT INTO sync_table (sync_date) VALUES (\(sTime));"
105
106
  }
106
- let lastId: Int64 = try UtilsSQLCipher.prepareSQL(
107
- mDB: mDB, sql: stmt, values: [], fromJson: false)
107
+ let resp = try UtilsSQLCipher.prepareSQL(
108
+ mDB: mDB, sql: stmt, values: [], fromJson: false,
109
+ returnMode: "no")
110
+ lastId = resp.0
108
111
  if lastId < 0 {
109
112
  throw ExportToJsonError.setLastExportDate(
110
113
  message: "lastId < 0")
@@ -149,9 +152,11 @@ class ExportToJson {
149
152
  // define the delete statement
150
153
  let delStmt = "DELETE FROM \(table) WHERE sql_deleted = 1 " +
151
154
  "AND last_modified < \(lastExportDate);"
152
- lastId = try UtilsSQLCipher.prepareSQL(mDB: mDB, sql: delStmt,
153
- values: [],
154
- fromJson: true)
155
+ let resp = try UtilsSQLCipher.prepareSQL(mDB: mDB, sql: delStmt,
156
+ values: [],
157
+ fromJson: true,
158
+ returnMode: "no")
159
+ lastId = resp.0
155
160
  if lastId < 0 {
156
161
  let msg = "DelExportedRows: lastId < 0"
157
162
  throw ExportToJsonError.delExportedRows(message: msg)