@capacitor-community/sqlite 5.0.7-2 → 5.0.7
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.
- package/README.md +6 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +123 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +112 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +140 -78
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +9 -9
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDelete.java +484 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDrop.java +3 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +169 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +4 -4
- package/dist/esm/definitions.d.ts +96 -11
- package/dist/esm/definitions.js +99 -50
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +44 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +143 -50
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +143 -50
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +600 -177
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +119 -0
- package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +128 -0
- package/ios/Plugin/Database.swift +76 -0
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +13 -2
- package/ios/Plugin/Utils/UtilsDelete.swift +116 -114
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +10 -3
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +84 -84
- package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -0
- package/package.json +2 -2
- package/src/definitions.ts +187 -53
- package/src/web.ts +48 -0
|
@@ -443,6 +443,125 @@ enum CapacitorSQLiteError: Error {
|
|
|
443
443
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
|
+
|
|
447
|
+
// MARK: - BeginTransaction
|
|
448
|
+
|
|
449
|
+
@objc public func beginTransaction(_ dbName: String) throws -> [String: Any] {
|
|
450
|
+
if isInit {
|
|
451
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
452
|
+
let connName: String = "RW_\(mDbName)"
|
|
453
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
454
|
+
let msg = "Connection to \(mDbName) not available"
|
|
455
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
456
|
+
}
|
|
457
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
458
|
+
do {
|
|
459
|
+
let res = try mDb.beginTransaction()
|
|
460
|
+
return ["changes": res]
|
|
461
|
+
} catch DatabaseError.beginTransaction(let message) {
|
|
462
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
463
|
+
} catch let error {
|
|
464
|
+
let msg: String = "\(error)"
|
|
465
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
466
|
+
}
|
|
467
|
+
} else {
|
|
468
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
469
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// MARK: - CommitTransaction
|
|
477
|
+
|
|
478
|
+
@objc public func commitTransaction(_ dbName: String) throws -> [String: Any] {
|
|
479
|
+
if isInit {
|
|
480
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
481
|
+
let connName: String = "RW_\(mDbName)"
|
|
482
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
483
|
+
let msg = "Connection to \(mDbName) not available"
|
|
484
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
485
|
+
}
|
|
486
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
487
|
+
do {
|
|
488
|
+
let res = try mDb.commitTransaction()
|
|
489
|
+
return ["changes": res]
|
|
490
|
+
} catch DatabaseError.commitTransaction(let message) {
|
|
491
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
492
|
+
} catch let error {
|
|
493
|
+
let msg: String = "\(error)"
|
|
494
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
498
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// MARK: - RollbackTransaction
|
|
506
|
+
|
|
507
|
+
@objc public func rollbackTransaction(_ dbName: String)
|
|
508
|
+
throws -> [String: Any] {
|
|
509
|
+
if isInit {
|
|
510
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
511
|
+
let connName: String = "RW_\(mDbName)"
|
|
512
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
513
|
+
let msg = "Connection to \(mDbName) not available"
|
|
514
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
515
|
+
}
|
|
516
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
517
|
+
do {
|
|
518
|
+
let res = try mDb.rollbackTransaction()
|
|
519
|
+
return ["changes": res]
|
|
520
|
+
} catch DatabaseError.rollbackTransaction(let message) {
|
|
521
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
522
|
+
} catch let error {
|
|
523
|
+
let msg: String = "\(error)"
|
|
524
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
525
|
+
}
|
|
526
|
+
} else {
|
|
527
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
528
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// MARK: - IsTransactionActive
|
|
536
|
+
|
|
537
|
+
@objc public func isTransactionActive(_ dbName: String) throws -> NSNumber {
|
|
538
|
+
if isInit {
|
|
539
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
540
|
+
let connName: String = "RW_\(mDbName)"
|
|
541
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
542
|
+
let msg = "Connection to \(mDbName) not available"
|
|
543
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
544
|
+
}
|
|
545
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
546
|
+
|
|
547
|
+
do {
|
|
548
|
+
let isAvail = try mDb.isAvailTrans()
|
|
549
|
+
if isAvail {
|
|
550
|
+
return 1
|
|
551
|
+
} else {
|
|
552
|
+
return 0
|
|
553
|
+
}
|
|
554
|
+
} catch DatabaseError.isAvailTrans(let message) {
|
|
555
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
556
|
+
}
|
|
557
|
+
} else {
|
|
558
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
559
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
560
|
+
}
|
|
561
|
+
} else {
|
|
562
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
563
|
+
}
|
|
564
|
+
}
|
|
446
565
|
|
|
447
566
|
// MARK: - getUrl
|
|
448
567
|
|
|
@@ -49,4 +49,8 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
|
|
|
49
49
|
CAP_PLUGIN_METHOD(isInConfigEncryption, CAPPluginReturnPromise);
|
|
50
50
|
CAP_PLUGIN_METHOD(isInConfigBiometricAuth, CAPPluginReturnPromise);
|
|
51
51
|
CAP_PLUGIN_METHOD(isDatabaseEncrypted, CAPPluginReturnPromise);
|
|
52
|
+
CAP_PLUGIN_METHOD(beginTransaction, CAPPluginReturnPromise);
|
|
53
|
+
CAP_PLUGIN_METHOD(commitTransaction, CAPPluginReturnPromise);
|
|
54
|
+
CAP_PLUGIN_METHOD(rollbackTransaction, CAPPluginReturnPromise);
|
|
55
|
+
CAP_PLUGIN_METHOD(isTransactionActive, CAPPluginReturnPromise);
|
|
52
56
|
)
|
|
@@ -322,6 +322,134 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
+
// MARK: - BeginTransaction
|
|
326
|
+
|
|
327
|
+
@objc func beginTransaction(_ call: CAPPluginCall) {
|
|
328
|
+
guard let dbName = call.options["database"] as? String else {
|
|
329
|
+
retHandler.rChanges(
|
|
330
|
+
call: call, ret: ["changes": -1],
|
|
331
|
+
message: "BeginTransaction: Must provide a database name")
|
|
332
|
+
return
|
|
333
|
+
}
|
|
334
|
+
do {
|
|
335
|
+
if let ret = try implementation?.beginTransaction(dbName) {
|
|
336
|
+
retHandler.rChanges(call: call, ret: ret)
|
|
337
|
+
return
|
|
338
|
+
} else {
|
|
339
|
+
retHandler.rChanges(
|
|
340
|
+
call: call, ret: ["changes": -1],
|
|
341
|
+
message: "BeginTransaction: Does not return a valid execute")
|
|
342
|
+
return
|
|
343
|
+
}
|
|
344
|
+
} catch CapacitorSQLiteError.failed(let message) {
|
|
345
|
+
let msg = "BeginTransaction: \(message)"
|
|
346
|
+
retHandler.rChanges(
|
|
347
|
+
call: call, ret: ["changes": -1],
|
|
348
|
+
message: msg)
|
|
349
|
+
return
|
|
350
|
+
} catch let error {
|
|
351
|
+
retHandler.rChanges(
|
|
352
|
+
call: call, ret: ["changes": -1],
|
|
353
|
+
message: "BeginTransaction: \(error)")
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// MARK: - CommitTransaction
|
|
359
|
+
|
|
360
|
+
@objc func commitTransaction(_ call: CAPPluginCall) {
|
|
361
|
+
guard let dbName = call.options["database"] as? String else {
|
|
362
|
+
retHandler.rChanges(
|
|
363
|
+
call: call, ret: ["changes": -1],
|
|
364
|
+
message: "CommitTransaction: Must provide a database name")
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
do {
|
|
368
|
+
if let ret = try implementation?.commitTransaction(dbName) {
|
|
369
|
+
retHandler.rChanges(call: call, ret: ret)
|
|
370
|
+
return
|
|
371
|
+
} else {
|
|
372
|
+
retHandler.rChanges(
|
|
373
|
+
call: call, ret: ["changes": -1],
|
|
374
|
+
message: "CommitTransaction: Does not return a valid execute")
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
} catch CapacitorSQLiteError.failed(let message) {
|
|
378
|
+
let msg = "CommitTransaction: \(message)"
|
|
379
|
+
retHandler.rChanges(
|
|
380
|
+
call: call, ret: ["changes": -1],
|
|
381
|
+
message: msg)
|
|
382
|
+
return
|
|
383
|
+
} catch let error {
|
|
384
|
+
retHandler.rChanges(
|
|
385
|
+
call: call, ret: ["changes": -1],
|
|
386
|
+
message: "CommitTransaction: \(error)")
|
|
387
|
+
return
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// MARK: - RollbackTransaction
|
|
392
|
+
|
|
393
|
+
@objc func rollbackTransaction(_ call: CAPPluginCall) {
|
|
394
|
+
guard let dbName = call.options["database"] as? String else {
|
|
395
|
+
retHandler.rChanges(
|
|
396
|
+
call: call, ret: ["changes": -1],
|
|
397
|
+
message: "RollbackTransaction: Must provide a database name")
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
do {
|
|
401
|
+
if let ret = try implementation?.rollbackTransaction(dbName) {
|
|
402
|
+
retHandler.rChanges(call: call, ret: ret)
|
|
403
|
+
return
|
|
404
|
+
} else {
|
|
405
|
+
retHandler.rChanges(
|
|
406
|
+
call: call, ret: ["changes": -1],
|
|
407
|
+
message: "RollbackTransaction: Does not return a valid execute")
|
|
408
|
+
return
|
|
409
|
+
}
|
|
410
|
+
} catch CapacitorSQLiteError.failed(let message) {
|
|
411
|
+
let msg = "RollbackTransaction: \(message)"
|
|
412
|
+
retHandler.rChanges(
|
|
413
|
+
call: call, ret: ["changes": -1],
|
|
414
|
+
message: msg)
|
|
415
|
+
return
|
|
416
|
+
} catch let error {
|
|
417
|
+
retHandler.rChanges(
|
|
418
|
+
call: call, ret: ["changes": -1],
|
|
419
|
+
message: "RollbackTransaction: \(error)")
|
|
420
|
+
return
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// MARK: - IsTransactionActive
|
|
425
|
+
|
|
426
|
+
@objc func isTransactionActive(_ call: CAPPluginCall) {
|
|
427
|
+
guard let dbName = call.options["database"] as? String else {
|
|
428
|
+
retHandler.rResult(
|
|
429
|
+
call: call,
|
|
430
|
+
message: "IsTransactionActive: Must provide a database name")
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
do {
|
|
434
|
+
let res = try implementation?.isTransactionActive(dbName)
|
|
435
|
+
var bRes: Bool = false
|
|
436
|
+
if res == 1 {
|
|
437
|
+
bRes = true
|
|
438
|
+
}
|
|
439
|
+
retHandler.rResult(call: call, ret: bRes)
|
|
440
|
+
return
|
|
441
|
+
} catch CapacitorSQLiteError.failed(let message) {
|
|
442
|
+
let msg = "IsTransactionActive: \(message)"
|
|
443
|
+
retHandler.rResult(call: call, message: msg)
|
|
444
|
+
return
|
|
445
|
+
} catch let error {
|
|
446
|
+
retHandler.rResult(
|
|
447
|
+
call: call,
|
|
448
|
+
message: "IsTransactionActive: \(error)")
|
|
449
|
+
return
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
325
453
|
// MARK: - GetUrl
|
|
326
454
|
|
|
327
455
|
@objc func getUrl(_ call: CAPPluginCall) {
|
|
@@ -25,6 +25,10 @@ enum DatabaseError: Error {
|
|
|
25
25
|
case importFromJson(message: String)
|
|
26
26
|
case getTableNames(message: String)
|
|
27
27
|
case deleteExportedRows(message: String)
|
|
28
|
+
case isAvailTrans(message: String)
|
|
29
|
+
case beginTransaction(message: String)
|
|
30
|
+
case commitTransaction(message: String)
|
|
31
|
+
case rollbackTransaction(message: String)
|
|
28
32
|
}
|
|
29
33
|
// swiftlint:disable file_length
|
|
30
34
|
// swiftlint:disable type_body_length
|
|
@@ -44,6 +48,7 @@ class Database {
|
|
|
44
48
|
let uUpg: UtilsUpgrade = UtilsUpgrade()
|
|
45
49
|
var readOnly: Bool = false
|
|
46
50
|
var ncDB: Bool = false
|
|
51
|
+
var isAvailableTransaction = false
|
|
47
52
|
|
|
48
53
|
// MARK: - Init
|
|
49
54
|
init(databaseLocation: String, databaseName: String,
|
|
@@ -221,6 +226,77 @@ class Database {
|
|
|
221
226
|
return
|
|
222
227
|
}
|
|
223
228
|
|
|
229
|
+
// MARK: - IsAvailTrans
|
|
230
|
+
|
|
231
|
+
func isAvailTrans() throws -> Bool {
|
|
232
|
+
if isOpen {
|
|
233
|
+
return isAvailableTransaction
|
|
234
|
+
} else {
|
|
235
|
+
let msg: String = "Failed in isAvailTrans database not opened"
|
|
236
|
+
throw DatabaseError.isAvailTrans(message: msg)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// MARK: - SetIsTransActive
|
|
241
|
+
|
|
242
|
+
func setIsTransActive(newValue: Bool ) {
|
|
243
|
+
isAvailableTransaction = newValue
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// MARK: - BeginTransaction
|
|
247
|
+
|
|
248
|
+
func beginTransaction() throws -> Int {
|
|
249
|
+
if isOpen {
|
|
250
|
+
do {
|
|
251
|
+
try UtilsSQLCipher.beginTransaction(mDB: self)
|
|
252
|
+
setIsTransActive(newValue: true)
|
|
253
|
+
return 0
|
|
254
|
+
} catch UtilsSQLCipherError.beginTransaction(let message) {
|
|
255
|
+
let msg: String = "Failed in beginTransaction \(message)"
|
|
256
|
+
throw DatabaseError.beginTransaction(message: msg)
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
let msg: String = "Failed in beginTransaction database not opened"
|
|
260
|
+
throw DatabaseError.beginTransaction(message: msg)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// MARK: - CommitTransaction
|
|
265
|
+
|
|
266
|
+
func commitTransaction() throws -> Int {
|
|
267
|
+
if isOpen {
|
|
268
|
+
do {
|
|
269
|
+
try UtilsSQLCipher.commitTransaction(mDB: self)
|
|
270
|
+
setIsTransActive(newValue: false)
|
|
271
|
+
return 0
|
|
272
|
+
} catch UtilsSQLCipherError.commitTransaction(let message) {
|
|
273
|
+
let msg: String = "Failed in commitTransaction \(message)"
|
|
274
|
+
throw DatabaseError.commitTransaction(message: msg)
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
let msg: String = "Failed in commitTransaction database not opened"
|
|
278
|
+
throw DatabaseError.commitTransaction(message: msg)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// MARK: - RollbackTransaction
|
|
283
|
+
|
|
284
|
+
func rollbackTransaction() throws -> Int {
|
|
285
|
+
if isOpen {
|
|
286
|
+
do {
|
|
287
|
+
try UtilsSQLCipher.rollbackTransaction(mDB: self)
|
|
288
|
+
setIsTransActive(newValue: false)
|
|
289
|
+
return 0
|
|
290
|
+
} catch UtilsSQLCipherError.rollbackTransaction(let message) {
|
|
291
|
+
let msg: String = "Failed in rollbackTransaction \(message)"
|
|
292
|
+
throw DatabaseError.rollbackTransaction(message: msg)
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
let msg: String = "Failed in rollbackTransaction database not opened"
|
|
296
|
+
throw DatabaseError.rollbackTransaction(message: msg)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
224
300
|
// MARK: - GetVersion
|
|
225
301
|
|
|
226
302
|
func getVersion () throws -> Int {
|
|
@@ -82,6 +82,7 @@ class ImportFromJson {
|
|
|
82
82
|
do {
|
|
83
83
|
// Start a transaction
|
|
84
84
|
try UtilsSQLCipher.beginTransaction(mDB: mDB)
|
|
85
|
+
mDB.setIsTransActive(newValue: true)
|
|
85
86
|
} catch UtilsSQLCipherError.beginTransaction(let message) {
|
|
86
87
|
throw ImportFromJsonError.createSchema(message: message)
|
|
87
88
|
}
|
|
@@ -103,7 +104,8 @@ class ImportFromJson {
|
|
|
103
104
|
// Rollback the transaction
|
|
104
105
|
try UtilsSQLCipher
|
|
105
106
|
.rollbackTransaction(mDB: mDB)
|
|
106
|
-
|
|
107
|
+
mDB.setIsTransActive(newValue: false)
|
|
108
|
+
} catch UtilsSQLCipherError
|
|
107
109
|
.rollbackTransaction(let message) {
|
|
108
110
|
throw ImportFromJsonError
|
|
109
111
|
.createSchema(message: message)
|
|
@@ -111,6 +113,7 @@ class ImportFromJson {
|
|
|
111
113
|
}
|
|
112
114
|
// Commit the transaction
|
|
113
115
|
try UtilsSQLCipher.commitTransaction(mDB: mDB)
|
|
116
|
+
mDB.setIsTransActive(newValue: false)
|
|
114
117
|
|
|
115
118
|
} catch UtilsSQLCipherError.execute(let message) {
|
|
116
119
|
var msg = message
|
|
@@ -118,6 +121,7 @@ class ImportFromJson {
|
|
|
118
121
|
// Rollback the transaction
|
|
119
122
|
try UtilsSQLCipher
|
|
120
123
|
.rollbackTransaction(mDB: mDB)
|
|
124
|
+
mDB.setIsTransActive(newValue: false)
|
|
121
125
|
throw ImportFromJsonError
|
|
122
126
|
.createSchema(message: message)
|
|
123
127
|
} catch UtilsSQLCipherError
|
|
@@ -135,6 +139,7 @@ class ImportFromJson {
|
|
|
135
139
|
changes = 0
|
|
136
140
|
// Commit the transaction
|
|
137
141
|
try UtilsSQLCipher.commitTransaction(mDB: mDB)
|
|
142
|
+
mDB.setIsTransActive(newValue: false)
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
return changes
|
|
@@ -314,6 +319,7 @@ class ImportFromJson {
|
|
|
314
319
|
initChanges = UtilsSQLCipher.dbChanges(mDB: mDB.mDb)
|
|
315
320
|
// Start a transaction
|
|
316
321
|
try UtilsSQLCipher.beginTransaction(mDB: mDB)
|
|
322
|
+
mDB.setIsTransActive(newValue: true)
|
|
317
323
|
} catch UtilsSQLCipherError.beginTransaction(let message) {
|
|
318
324
|
throw ImportFromJsonError.createDatabaseData(message: message)
|
|
319
325
|
}
|
|
@@ -341,6 +347,7 @@ class ImportFromJson {
|
|
|
341
347
|
// Rollback the transaction
|
|
342
348
|
try UtilsSQLCipher
|
|
343
349
|
.rollbackTransaction(mDB: mDB)
|
|
350
|
+
mDB.setIsTransActive(newValue: false)
|
|
344
351
|
throw ImportFromJsonError
|
|
345
352
|
.createDatabaseData(message: message)
|
|
346
353
|
} catch UtilsSQLCipherError
|
|
@@ -359,6 +366,7 @@ class ImportFromJson {
|
|
|
359
366
|
do {
|
|
360
367
|
// Commit the transaction
|
|
361
368
|
try UtilsSQLCipher.commitTransaction(mDB: mDB)
|
|
369
|
+
mDB.setIsTransActive(newValue: false)
|
|
362
370
|
changes = UtilsSQLCipher.dbChanges(mDB: mDB.mDb) -
|
|
363
371
|
initChanges
|
|
364
372
|
let msg = "Tables data creation completed changes: \(changes)"
|
|
@@ -566,6 +574,7 @@ class ImportFromJson {
|
|
|
566
574
|
initChanges = UtilsSQLCipher.dbChanges(mDB: mDB.mDb)
|
|
567
575
|
// Start a transaction
|
|
568
576
|
try UtilsSQLCipher.beginTransaction(mDB: mDB)
|
|
577
|
+
mDB.setIsTransActive(newValue: true)
|
|
569
578
|
} catch UtilsSQLCipherError.beginTransaction(let message) {
|
|
570
579
|
throw ImportFromJsonError.createDatabaseData(message: message)
|
|
571
580
|
}
|
|
@@ -590,6 +599,7 @@ class ImportFromJson {
|
|
|
590
599
|
do {
|
|
591
600
|
// Commit the transaction
|
|
592
601
|
try UtilsSQLCipher.commitTransaction(mDB: mDB)
|
|
602
|
+
mDB.setIsTransActive(newValue: false)
|
|
593
603
|
changes = UtilsSQLCipher
|
|
594
604
|
.dbChanges(mDB: mDB.mDb) - initChanges
|
|
595
605
|
} catch UtilsSQLCipherError.commitTransaction(
|
|
@@ -604,7 +614,8 @@ class ImportFromJson {
|
|
|
604
614
|
// Rollback the transaction
|
|
605
615
|
try UtilsSQLCipher
|
|
606
616
|
.rollbackTransaction(mDB: mDB)
|
|
607
|
-
|
|
617
|
+
mDB.setIsTransActive(newValue: false)
|
|
618
|
+
throw ImportFromJsonError
|
|
608
619
|
.createViews(message: msg)
|
|
609
620
|
} catch UtilsSQLCipherError
|
|
610
621
|
.rollbackTransaction(let message) {
|