@capacitor-community/sqlite 4.1.0-4 → 4.1.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 +8 -5
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +160 -92
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +41 -21
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +92 -107
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +36 -319
- package/dist/esm/definitions.d.ts +32 -15
- package/dist/esm/definitions.js +191 -105
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +191 -105
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +191 -105
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +47 -332
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +123 -59
- package/ios/Plugin/CapacitorSQLitePlugin.swift +53 -20
- package/ios/Plugin/Database.swift +15 -11
- package/ios/Plugin/Utils/UtilsUpgrade.swift +36 -369
- package/package.json +2 -2
|
@@ -281,7 +281,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
281
281
|
if isInit {
|
|
282
282
|
|
|
283
283
|
// check if the connection already exists
|
|
284
|
-
let
|
|
284
|
+
let connName: String = "RO_\(databasePath)"
|
|
285
|
+
let conn = dbDict[connName]
|
|
285
286
|
if conn != nil {
|
|
286
287
|
let msg = "Connection \(databasePath) already exists"
|
|
287
288
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
@@ -298,9 +299,9 @@ enum CapacitorSQLiteError: Error {
|
|
|
298
299
|
databaseLocation: databaseLocation,
|
|
299
300
|
databaseName: databasePath,
|
|
300
301
|
encrypted: false, isEncryption: isEncryption, account: account,
|
|
301
|
-
mode: "no-encryption", version: version,
|
|
302
|
+
mode: "no-encryption", version: version, readonly: true,
|
|
302
303
|
vUpgDict: [:])
|
|
303
|
-
dbDict[
|
|
304
|
+
dbDict[connName] = mDb
|
|
304
305
|
return
|
|
305
306
|
} catch let error {
|
|
306
307
|
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
@@ -314,7 +315,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
314
315
|
|
|
315
316
|
@objc public func closeNCConnection(_ dbName: String) throws {
|
|
316
317
|
if isInit {
|
|
317
|
-
|
|
318
|
+
let connName: String = "RO_\(dbName)"
|
|
319
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
318
320
|
let msg = "Connection to \(dbName) not available"
|
|
319
321
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
320
322
|
}
|
|
@@ -325,7 +327,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
325
327
|
throw CapacitorSQLiteError.failed(message: message)
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
|
-
dbDict.removeValue(forKey:
|
|
330
|
+
dbDict.removeValue(forKey: connName)
|
|
329
331
|
return
|
|
330
332
|
} else {
|
|
331
333
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
@@ -334,15 +336,18 @@ enum CapacitorSQLiteError: Error {
|
|
|
334
336
|
|
|
335
337
|
// MARK: - CreateConnection
|
|
336
338
|
|
|
339
|
+
// swiftlint:disable function_parameter_count
|
|
337
340
|
@objc public func createConnection(_ dbName: String,
|
|
338
341
|
encrypted: Bool,
|
|
339
342
|
mode: String,
|
|
340
343
|
version: Int,
|
|
341
|
-
vUpgDict: [Int: [String: Any]]
|
|
344
|
+
vUpgDict: [Int: [String: Any]],
|
|
345
|
+
readonly: Bool) throws {
|
|
342
346
|
if isInit {
|
|
343
347
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
344
348
|
// check if the connection already exists
|
|
345
|
-
let
|
|
349
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
350
|
+
let conn = dbDict[connName]
|
|
346
351
|
if conn != nil {
|
|
347
352
|
let msg = "Connection \(mDbName) already exists"
|
|
348
353
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
@@ -356,9 +361,10 @@ enum CapacitorSQLiteError: Error {
|
|
|
356
361
|
databaseLocation: databaseLocation,
|
|
357
362
|
databaseName: "\(mDbName)SQLite.db",
|
|
358
363
|
encrypted: encrypted, isEncryption: isEncryption, account: account,
|
|
359
|
-
mode: mode, version: version,
|
|
364
|
+
mode: mode, version: version, readonly: readonly,
|
|
360
365
|
vUpgDict: vUpgDict)
|
|
361
|
-
|
|
366
|
+
|
|
367
|
+
dbDict[connName] = mDb
|
|
362
368
|
return
|
|
363
369
|
} catch let error {
|
|
364
370
|
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
@@ -367,13 +373,15 @@ enum CapacitorSQLiteError: Error {
|
|
|
367
373
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
368
374
|
}
|
|
369
375
|
}
|
|
376
|
+
// swiftlint:enable function_parameter_count
|
|
370
377
|
|
|
371
378
|
// MARK: - Open
|
|
372
379
|
|
|
373
|
-
@objc public func open(_ dbName: String) throws {
|
|
380
|
+
@objc public func open(_ dbName: String, readonly: Bool) throws {
|
|
374
381
|
if isInit {
|
|
375
382
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
376
|
-
|
|
383
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
384
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
377
385
|
let msg = "Connection to \(mDbName) not available"
|
|
378
386
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
379
387
|
}
|
|
@@ -390,10 +398,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
390
398
|
|
|
391
399
|
// MARK: - Close
|
|
392
400
|
|
|
393
|
-
@objc public func close(_ dbName: String) throws {
|
|
401
|
+
@objc public func close(_ dbName: String, readonly: Bool) throws {
|
|
394
402
|
if isInit {
|
|
395
403
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
396
|
-
|
|
404
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
405
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
397
406
|
let msg = "Connection to \(mDbName) not available"
|
|
398
407
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
399
408
|
}
|
|
@@ -410,10 +419,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
410
419
|
|
|
411
420
|
// MARK: - getUrl
|
|
412
421
|
|
|
413
|
-
@objc public func getUrl(_ dbName: String) throws -> String {
|
|
422
|
+
@objc public func getUrl(_ dbName: String, readonly: Bool) throws -> String {
|
|
414
423
|
if isInit {
|
|
415
424
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
416
|
-
|
|
425
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
426
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
417
427
|
let msg = "Connection to \(mDbName) not available"
|
|
418
428
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
419
429
|
}
|
|
@@ -426,10 +436,12 @@ enum CapacitorSQLiteError: Error {
|
|
|
426
436
|
|
|
427
437
|
// MARK: - GetVersion
|
|
428
438
|
|
|
429
|
-
@objc public func getVersion(_ dbName: String
|
|
439
|
+
@objc public func getVersion(_ dbName: String, readonly: Bool)
|
|
440
|
+
throws -> NSNumber {
|
|
430
441
|
if isInit {
|
|
431
442
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
432
|
-
|
|
443
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
444
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
433
445
|
let msg = "Connection to \(mDbName) not available"
|
|
434
446
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
435
447
|
}
|
|
@@ -447,10 +459,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
447
459
|
|
|
448
460
|
// MARK: - Close Connection
|
|
449
461
|
|
|
450
|
-
@objc public func closeConnection(_ dbName: String) throws {
|
|
462
|
+
@objc public func closeConnection(_ dbName: String, readonly: Bool) throws {
|
|
451
463
|
if isInit {
|
|
452
464
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
453
|
-
|
|
465
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
466
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
454
467
|
return
|
|
455
468
|
}
|
|
456
469
|
if mDb.isDBOpen() {
|
|
@@ -460,7 +473,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
460
473
|
throw CapacitorSQLiteError.failed(message: message)
|
|
461
474
|
}
|
|
462
475
|
}
|
|
463
|
-
dbDict.removeValue(forKey:
|
|
476
|
+
dbDict.removeValue(forKey: connName)
|
|
464
477
|
return
|
|
465
478
|
} else {
|
|
466
479
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
@@ -549,10 +562,12 @@ enum CapacitorSQLiteError: Error {
|
|
|
549
562
|
|
|
550
563
|
// MARK: - IsTableExists
|
|
551
564
|
|
|
552
|
-
@objc public func isTableExists(_ dbName: String, tableName: String
|
|
565
|
+
@objc public func isTableExists(_ dbName: String, tableName: String,
|
|
566
|
+
readonly: Bool) throws -> NSNumber {
|
|
553
567
|
if isInit {
|
|
554
568
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
555
|
-
|
|
569
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
570
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
556
571
|
let msg = "Connection to \(mDbName) not available"
|
|
557
572
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
558
573
|
}
|
|
@@ -582,14 +597,19 @@ enum CapacitorSQLiteError: Error {
|
|
|
582
597
|
// MARK: - Execute
|
|
583
598
|
|
|
584
599
|
@objc public func execute(_ dbName: String, statements: String,
|
|
585
|
-
transaction: Bool)
|
|
600
|
+
transaction: Bool, readonly: Bool)
|
|
586
601
|
throws -> [String: Any] {
|
|
587
602
|
if isInit {
|
|
588
603
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
589
|
-
|
|
604
|
+
let connName: String = "RW_\(mDbName)"
|
|
605
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
590
606
|
let msg = "Connection to \(mDbName) not available"
|
|
591
607
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
592
608
|
}
|
|
609
|
+
if readonly {
|
|
610
|
+
let msg = "not allowed in read-only mode"
|
|
611
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
612
|
+
}
|
|
593
613
|
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
594
614
|
do {
|
|
595
615
|
var stmts = statements
|
|
@@ -625,14 +645,19 @@ enum CapacitorSQLiteError: Error {
|
|
|
625
645
|
// MARK: - ExecuteSet
|
|
626
646
|
|
|
627
647
|
@objc func executeSet(_ dbName: String, set: [[String: Any]],
|
|
628
|
-
transaction: Bool)
|
|
648
|
+
transaction: Bool, readonly: Bool)
|
|
629
649
|
throws -> [String: Any] {
|
|
630
650
|
if isInit {
|
|
631
651
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
632
|
-
|
|
652
|
+
let connName: String = "RW_\(mDbName)"
|
|
653
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
633
654
|
let msg = "Connection to \(mDbName) not available"
|
|
634
655
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
635
656
|
}
|
|
657
|
+
if readonly {
|
|
658
|
+
let msg = "not allowed in read-only mode"
|
|
659
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
660
|
+
}
|
|
636
661
|
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
637
662
|
do {
|
|
638
663
|
let res = try mDb.execSet(set: set, transaction: transaction)
|
|
@@ -654,16 +679,22 @@ enum CapacitorSQLiteError: Error {
|
|
|
654
679
|
|
|
655
680
|
// MARK: - Run
|
|
656
681
|
|
|
682
|
+
// swiftlint:disable function_body_length
|
|
657
683
|
// swiftlint:disable cyclomatic_complexity
|
|
658
684
|
@objc func run(_ dbName: String, statement: String, values: [Any],
|
|
659
|
-
transaction: Bool)
|
|
685
|
+
transaction: Bool, readonly: Bool)
|
|
660
686
|
throws -> [String: Any] {
|
|
661
687
|
if isInit {
|
|
662
688
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
663
|
-
|
|
689
|
+
let connName: String = "RW_\(mDbName)"
|
|
690
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
664
691
|
let msg = "Connection to \(mDbName) not available"
|
|
665
692
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
666
693
|
}
|
|
694
|
+
if readonly {
|
|
695
|
+
let msg = "not allowed in read-only mode"
|
|
696
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
697
|
+
}
|
|
667
698
|
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
668
699
|
do {
|
|
669
700
|
var val: [Any] = []
|
|
@@ -705,14 +736,16 @@ enum CapacitorSQLiteError: Error {
|
|
|
705
736
|
}
|
|
706
737
|
}
|
|
707
738
|
// swiftlint:enable cyclomatic_complexity
|
|
739
|
+
// swiftlint:enable function_body_length
|
|
708
740
|
|
|
709
741
|
// MARK: - Query
|
|
710
742
|
|
|
711
743
|
@objc func query(_ dbName: String, statement: String,
|
|
712
|
-
values: [Any]) throws -> [[String: Any]] {
|
|
744
|
+
values: [Any], readonly: Bool) throws -> [[String: Any]] {
|
|
713
745
|
if isInit {
|
|
714
746
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
715
|
-
|
|
747
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
748
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
716
749
|
let msg = "Connection to \(mDbName) not available"
|
|
717
750
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
718
751
|
}
|
|
@@ -738,10 +771,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
738
771
|
|
|
739
772
|
// MARK: - isDBExists
|
|
740
773
|
|
|
741
|
-
@objc func isDBExists(_ dbName: String) throws -> NSNumber {
|
|
774
|
+
@objc func isDBExists(_ dbName: String, readonly: Bool) throws -> NSNumber {
|
|
742
775
|
if isInit {
|
|
743
776
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
744
|
-
|
|
777
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
778
|
+
guard let _: Database = dbDict[connName] else {
|
|
745
779
|
let msg = "Connection to \(mDbName) not available"
|
|
746
780
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
747
781
|
}
|
|
@@ -760,10 +794,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
760
794
|
|
|
761
795
|
// MARK: - isDBOpen
|
|
762
796
|
|
|
763
|
-
|
|
797
|
+
@objc func isDBOpen(_ dbName: String, readonly: Bool) throws -> NSNumber {
|
|
764
798
|
if isInit {
|
|
765
799
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
766
|
-
|
|
800
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
801
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
767
802
|
let msg = "Connection to \(mDbName) not available"
|
|
768
803
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
769
804
|
}
|
|
@@ -780,14 +815,20 @@ enum CapacitorSQLiteError: Error {
|
|
|
780
815
|
|
|
781
816
|
// MARK: - deleteDatabase
|
|
782
817
|
|
|
783
|
-
|
|
818
|
+
// swiftlint:disable function_body_length
|
|
819
|
+
// swiftlint:disable cyclomatic_complexity
|
|
820
|
+
@objc func deleteDatabase(_ dbName: String, readonly: Bool) throws {
|
|
784
821
|
if isInit {
|
|
785
822
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
786
|
-
|
|
823
|
+
let connName: String = "RW_\(mDbName)"
|
|
824
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
787
825
|
let msg = "Connection to \(mDbName) not available"
|
|
788
826
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
789
827
|
}
|
|
790
|
-
|
|
828
|
+
if readonly {
|
|
829
|
+
let msg = "not allowed in read-only mode"
|
|
830
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
831
|
+
}
|
|
791
832
|
do {
|
|
792
833
|
if !mDb.isDBOpen() {
|
|
793
834
|
// check the state of the DB
|
|
@@ -829,6 +870,8 @@ enum CapacitorSQLiteError: Error {
|
|
|
829
870
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
830
871
|
}
|
|
831
872
|
}
|
|
873
|
+
// swiftlint:enable cyclomatic_complexity
|
|
874
|
+
// swiftlint:enable function_body_length
|
|
832
875
|
|
|
833
876
|
// MARK: - isJsonValid
|
|
834
877
|
|
|
@@ -879,14 +922,18 @@ enum CapacitorSQLiteError: Error {
|
|
|
879
922
|
let inMode: String = encrypted ? "secret"
|
|
880
923
|
: "no-encryption"
|
|
881
924
|
let version: Int = jsonSQLite[0].version
|
|
882
|
-
var dbName: String = CapacitorSQLite.getDatabaseName(
|
|
925
|
+
var dbName: String = CapacitorSQLite.getDatabaseName(
|
|
926
|
+
dbName: jsonSQLite[0].database
|
|
927
|
+
)
|
|
883
928
|
dbName.append("SQLite.db")
|
|
884
929
|
// open the database
|
|
885
930
|
do {
|
|
886
931
|
mDb = try Database(
|
|
887
932
|
databaseLocation: databaseLocation, databaseName: dbName,
|
|
888
|
-
encrypted: encrypted, isEncryption: isEncryption,
|
|
889
|
-
|
|
933
|
+
encrypted: encrypted, isEncryption: isEncryption,
|
|
934
|
+
account: account,
|
|
935
|
+
mode: inMode, version: version, readonly: false,
|
|
936
|
+
vUpgDict: [:])
|
|
890
937
|
if overwrite && mode == "full" {
|
|
891
938
|
let isExists = UtilsFile
|
|
892
939
|
.isFileExist(databaseLocation: databaseLocation,
|
|
@@ -972,11 +1019,12 @@ enum CapacitorSQLiteError: Error {
|
|
|
972
1019
|
|
|
973
1020
|
// MARK: - exportToJson
|
|
974
1021
|
|
|
975
|
-
@objc func exportToJson(_ dbName: String, expMode: String)
|
|
1022
|
+
@objc func exportToJson(_ dbName: String, expMode: String, readonly: Bool)
|
|
976
1023
|
throws -> [String: Any] {
|
|
977
1024
|
if isInit {
|
|
978
1025
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
979
|
-
|
|
1026
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
1027
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
980
1028
|
let msg = "Connection to \(mDbName) not available"
|
|
981
1029
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
982
1030
|
}
|
|
@@ -1015,13 +1063,18 @@ enum CapacitorSQLiteError: Error {
|
|
|
1015
1063
|
|
|
1016
1064
|
// MARK: - deleteExportedRows
|
|
1017
1065
|
|
|
1018
|
-
@objc func deleteExportedRows(_ dbName: String) throws {
|
|
1066
|
+
@objc func deleteExportedRows(_ dbName: String, readonly: Bool) throws {
|
|
1019
1067
|
if isInit {
|
|
1020
1068
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
1021
|
-
|
|
1069
|
+
let connName: String = "RW_\(mDbName)"
|
|
1070
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
1022
1071
|
let msg = "Connection to \(mDbName) not available"
|
|
1023
1072
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1024
1073
|
}
|
|
1074
|
+
if readonly {
|
|
1075
|
+
let msg = "not allowed in read-only mode"
|
|
1076
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1077
|
+
}
|
|
1025
1078
|
if mDb.isDBOpen() {
|
|
1026
1079
|
do {
|
|
1027
1080
|
try mDb.deleteExportedRows()
|
|
@@ -1042,13 +1095,18 @@ enum CapacitorSQLiteError: Error {
|
|
|
1042
1095
|
|
|
1043
1096
|
// MARK: - createSyncTable
|
|
1044
1097
|
|
|
1045
|
-
@objc func createSyncTable(_ dbName: String) throws -> NSNumber {
|
|
1098
|
+
@objc func createSyncTable(_ dbName: String, readonly: Bool) throws -> NSNumber {
|
|
1046
1099
|
if isInit {
|
|
1047
1100
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
1048
|
-
|
|
1101
|
+
let connName: String = "RW_\(mDbName)"
|
|
1102
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
1049
1103
|
let msg = "Connection to \(mDbName) not available"
|
|
1050
1104
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1051
1105
|
}
|
|
1106
|
+
if readonly {
|
|
1107
|
+
let msg = "not allowed in read-only mode"
|
|
1108
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1109
|
+
}
|
|
1052
1110
|
if mDb.isDBOpen() {
|
|
1053
1111
|
do {
|
|
1054
1112
|
let res: Int = try mDb.createSyncTable()
|
|
@@ -1070,14 +1128,19 @@ enum CapacitorSQLiteError: Error {
|
|
|
1070
1128
|
|
|
1071
1129
|
// MARK: - setSyncDate
|
|
1072
1130
|
|
|
1073
|
-
@objc func setSyncDate(_ dbName: String, syncDate: String)
|
|
1131
|
+
@objc func setSyncDate(_ dbName: String, syncDate: String, readonly: Bool)
|
|
1074
1132
|
throws {
|
|
1075
1133
|
if isInit {
|
|
1076
1134
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
1077
|
-
|
|
1135
|
+
let connName: String = "RW_\(mDbName)"
|
|
1136
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
1078
1137
|
let msg = "Connection to \(mDbName) not available"
|
|
1079
1138
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1080
1139
|
}
|
|
1140
|
+
if readonly {
|
|
1141
|
+
let msg = "not allowed in read-only mode"
|
|
1142
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1143
|
+
}
|
|
1081
1144
|
if mDb.isDBOpen() {
|
|
1082
1145
|
|
|
1083
1146
|
do {
|
|
@@ -1106,10 +1169,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
1106
1169
|
|
|
1107
1170
|
// MARK: - getSyncDate
|
|
1108
1171
|
|
|
1109
|
-
@objc func getSyncDate(_ dbName: String) throws -> NSNumber {
|
|
1172
|
+
@objc func getSyncDate(_ dbName: String, readonly: Bool) throws -> NSNumber {
|
|
1110
1173
|
if isInit {
|
|
1111
1174
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
1112
|
-
|
|
1175
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
1176
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
1113
1177
|
let msg = "Connection to \(mDbName) not available"
|
|
1114
1178
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1115
1179
|
}
|
|
@@ -1146,23 +1210,21 @@ enum CapacitorSQLiteError: Error {
|
|
|
1146
1210
|
var upgDict: [String: Any] = [:]
|
|
1147
1211
|
for dict in upgrade {
|
|
1148
1212
|
let keys = dict.keys
|
|
1149
|
-
if !(keys.contains("
|
|
1150
|
-
!(keys.contains("toVersion")) ||
|
|
1151
|
-
!(keys.contains("statement")) {
|
|
1213
|
+
if !(keys.contains("toVersion")) || !(keys.contains("statements")) {
|
|
1152
1214
|
var msg: String = "upgrade must have keys in "
|
|
1153
|
-
msg.append("{
|
|
1215
|
+
msg.append("{toVersion,statements}")
|
|
1154
1216
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1155
1217
|
}
|
|
1156
1218
|
for (key, value) in dict {
|
|
1157
1219
|
upgDict[key] = value
|
|
1158
1220
|
}
|
|
1159
1221
|
}
|
|
1160
|
-
guard let
|
|
1161
|
-
let msg: String = "
|
|
1222
|
+
guard let toVersion = upgDict["toVersion"] as? Int else {
|
|
1223
|
+
let msg: String = "toVersion key must be an Int"
|
|
1162
1224
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1163
1225
|
}
|
|
1164
1226
|
let upgVersionDict: [Int: [String: Any]] =
|
|
1165
|
-
[
|
|
1227
|
+
[toVersion: upgDict]
|
|
1166
1228
|
return upgVersionDict
|
|
1167
1229
|
} else {
|
|
1168
1230
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
@@ -1228,10 +1290,12 @@ enum CapacitorSQLiteError: Error {
|
|
|
1228
1290
|
|
|
1229
1291
|
// MARK: - getTableList
|
|
1230
1292
|
|
|
1231
|
-
@objc func getTableList(_ dbName: String
|
|
1293
|
+
@objc func getTableList(_ dbName: String, readonly: Bool)
|
|
1294
|
+
throws -> [String] {
|
|
1232
1295
|
if isInit {
|
|
1233
1296
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
1234
|
-
|
|
1297
|
+
let connName: String = readonly ? "RO_\(mDbName)" : "RW_\(mDbName)"
|
|
1298
|
+
guard let mDb: Database = dbDict[connName] else {
|
|
1235
1299
|
let msg = "Connection to \(mDbName) not available"
|
|
1236
1300
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
1237
1301
|
}
|