@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
|
@@ -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,
|
|
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
|
|
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,
|
|
50
|
-
|
|
51
|
-
|
|
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,20 +136,21 @@ class Database {
|
|
|
133
136
|
try UtilsSQLCipher
|
|
134
137
|
.setForeignKeyConstraintsEnabled(mDB: self,
|
|
135
138
|
toggle: true)
|
|
136
|
-
if !ncDB {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if curVersion == 0 {
|
|
140
|
-
try UtilsSQLCipher.setVersion(mDB: self, version: 1)
|
|
141
|
-
curVersion = try UtilsSQLCipher.getVersion(mDB: self)
|
|
142
|
-
}
|
|
139
|
+
if !ncDB && !self.readOnly {
|
|
140
|
+
let curVersion: Int = try UtilsSQLCipher.getVersion(mDB: self)
|
|
141
|
+
|
|
143
142
|
if dbVersion > curVersion && vUpgDict.count > 0 {
|
|
143
|
+
// backup the database
|
|
144
|
+
_ = try UtilsFile.copyFile(fileName: dbName,
|
|
145
|
+
toFileName: "backup-\(dbName)",
|
|
146
|
+
databaseLocation: databaseLocation)
|
|
147
|
+
|
|
144
148
|
_ = try uUpg
|
|
145
149
|
.onUpgrade(mDB: self, upgDict: vUpgDict,
|
|
146
|
-
dbName: dbName,
|
|
147
150
|
currentVersion: curVersion,
|
|
148
151
|
targetVersion: dbVersion,
|
|
149
152
|
databaseLocation: databaseLocation)
|
|
153
|
+
|
|
150
154
|
try UtilsSQLCipher
|
|
151
155
|
.deleteBackupDB(databaseLocation: databaseLocation,
|
|
152
156
|
databaseName: dbName)
|