@capacitor-community/sqlite 3.2.5-1 → 3.3.2
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/CHANGELOG.md +45 -0
- package/CapacitorCommunitySqlite.podspec +1 -0
- package/README.md +26 -117
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +5 -5
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +3 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +0 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +71 -11
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsMigrate.java +34 -15
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +0 -1
- package/dist/esm/definitions.d.ts +13 -4
- package/dist/esm/definitions.js +3 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -2
- package/dist/esm/web.js +2 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +5 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +5 -4
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +69 -25
- package/electron/dist/plugin.js.map +1 -1
- package/electron/rollup.config.js +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +19 -5
- package/ios/Plugin/CapacitorSQLitePlugin.swift +3 -1
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +0 -1
- package/ios/Plugin/Utils/UtilsFile.swift +98 -34
- package/ios/Plugin/Utils/UtilsMigrate.swift +59 -13
- package/ios/Plugin/Utils/UtilsSecret.swift +2 -8
- package/package.json +5 -5
|
@@ -676,7 +676,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
676
676
|
|
|
677
677
|
// MARK: - copyFromAssets
|
|
678
678
|
|
|
679
|
-
@objc func copyFromAssets() throws {
|
|
679
|
+
@objc func copyFromAssets(overwrite: Bool) throws {
|
|
680
680
|
|
|
681
681
|
// check if the assets/database folder exists
|
|
682
682
|
do {
|
|
@@ -687,7 +687,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
687
687
|
if bRes {
|
|
688
688
|
// get the database files
|
|
689
689
|
let dbList: [String] = try UtilsFile
|
|
690
|
-
.getFileList(path: aPath)
|
|
690
|
+
.getFileList(path: aPath, ext: ".db")
|
|
691
691
|
// loop through the database files
|
|
692
692
|
for mDb in dbList {
|
|
693
693
|
// for each check if the suffix SQLite.db is there
|
|
@@ -698,13 +698,27 @@ enum CapacitorSQLiteError: Error {
|
|
|
698
698
|
// database folder
|
|
699
699
|
_ = try UtilsFile
|
|
700
700
|
.copyFromAssetToDatabase(fromDb: mDb,
|
|
701
|
-
toDb: toDb)
|
|
701
|
+
toDb: toDb, overwrite: overwrite)
|
|
702
|
+
}
|
|
703
|
+
// get the zip files
|
|
704
|
+
let zipList: [String] = try UtilsFile
|
|
705
|
+
.getFileList(path: aPath, ext: ".zip")
|
|
706
|
+
// loop through the database files
|
|
707
|
+
for zip in zipList {
|
|
708
|
+
// for each zip uncompress the file to the Application
|
|
709
|
+
// database folder
|
|
710
|
+
_ = try UtilsFile
|
|
711
|
+
.unzipFromAssetToDatabase(zip: zip, overwrite: overwrite)
|
|
702
712
|
}
|
|
703
713
|
return
|
|
704
714
|
} else {
|
|
705
715
|
let msg: String = "assets database path does not exist"
|
|
706
716
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
707
717
|
}
|
|
718
|
+
} catch UtilsFileError.copyFromAssetToDatabaseFailed(let message) {
|
|
719
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
720
|
+
} catch UtilsFileError.unzipFromAssetToDatabaseFailed(let message) {
|
|
721
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
708
722
|
} catch let error {
|
|
709
723
|
let msg: String = "\(error)"
|
|
710
724
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
@@ -717,7 +731,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
717
731
|
do {
|
|
718
732
|
let aPath: String = try UtilsFile.getDatabasesPath()
|
|
719
733
|
// get the database files
|
|
720
|
-
let dbList: [String] = try UtilsFile.getFileList(path: aPath)
|
|
734
|
+
let dbList: [String] = try UtilsFile.getFileList(path: aPath, ext: ".db")
|
|
721
735
|
return dbList
|
|
722
736
|
|
|
723
737
|
} catch let error {
|
|
@@ -792,7 +806,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
792
806
|
}
|
|
793
807
|
|
|
794
808
|
func closeAllConnections() throws {
|
|
795
|
-
|
|
809
|
+
let keys: [String] = Array(self.dbDict.keys)
|
|
796
810
|
|
|
797
811
|
for key in keys {
|
|
798
812
|
guard let mDb: Database = dbDict[key] else {
|
|
@@ -949,8 +949,10 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
949
949
|
// MARK: copyFromAssets
|
|
950
950
|
|
|
951
951
|
@objc func copyFromAssets(_ call: CAPPluginCall) {
|
|
952
|
+
let overwrite: Bool = call.getBool("overwrite") ?? true
|
|
953
|
+
|
|
952
954
|
do {
|
|
953
|
-
try implementation.copyFromAssets()
|
|
955
|
+
try implementation.copyFromAssets(overwrite: overwrite)
|
|
954
956
|
retHandler.rResult(call: call)
|
|
955
957
|
return
|
|
956
958
|
} catch CapacitorSQLiteError.failed(let message) {
|
|
@@ -706,7 +706,6 @@ class ExportToJson {
|
|
|
706
706
|
after: oPar)..<cPar]
|
|
707
707
|
row[1] = rstr[rstr.index(
|
|
708
708
|
cPar, offsetBy: 2)..<rstr.endIndex]
|
|
709
|
-
print("row[0] \(row[0]) row[1] \(row[1]) ")
|
|
710
709
|
columns["foreignkey"] = String(row[0])
|
|
711
710
|
}
|
|
712
711
|
columns["value"] = String(row[1]).replacingOccurrences(of: "§", with: ",")
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
//
|
|
8
8
|
|
|
9
9
|
import Foundation
|
|
10
|
+
import ZIPFoundation
|
|
11
|
+
|
|
10
12
|
enum UtilsFileError: Error {
|
|
11
13
|
case getFilePathFailed
|
|
12
14
|
case copyFileFailed
|
|
@@ -20,9 +22,11 @@ enum UtilsFileError: Error {
|
|
|
20
22
|
case getLibraryPathFailed
|
|
21
23
|
case getLibraryURLFailed
|
|
22
24
|
case getFileListFailed
|
|
23
|
-
case copyFromAssetToDatabaseFailed
|
|
25
|
+
case copyFromAssetToDatabaseFailed(message: String)
|
|
26
|
+
case unzipFromAssetToDatabaseFailed(message: String)
|
|
24
27
|
case copyFromNamesFailed
|
|
25
28
|
}
|
|
29
|
+
// swiftlint:disable file_length
|
|
26
30
|
// swiftlint:disable type_body_length
|
|
27
31
|
class UtilsFile {
|
|
28
32
|
|
|
@@ -165,13 +169,10 @@ class UtilsFile {
|
|
|
165
169
|
|
|
166
170
|
class func setPathSuffix(sDb: String ) -> String {
|
|
167
171
|
var toDb: String = sDb
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if sDb.hasSuffix(ext) {
|
|
173
|
-
toDb = sDb.prefix(sDb.count - ext.count) + "SQLite.db"
|
|
174
|
-
}
|
|
172
|
+
let ext: String = ".db"
|
|
173
|
+
if sDb.hasSuffix(ext) {
|
|
174
|
+
if !sDb.contains("SQLite.db") {
|
|
175
|
+
toDb = sDb.prefix(sDb.count - ext.count) + "SQLite.db"
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
return toDb
|
|
@@ -179,18 +180,24 @@ class UtilsFile {
|
|
|
179
180
|
|
|
180
181
|
// MARK: - GetFileList
|
|
181
182
|
|
|
182
|
-
class func getFileList(path: String) throws -> [String] {
|
|
183
|
+
class func getFileList(path: String, ext: String? = nil) throws -> [String] {
|
|
184
|
+
|
|
183
185
|
do {
|
|
184
|
-
var
|
|
186
|
+
var files: [String] = []
|
|
185
187
|
let filenames = try FileManager.default
|
|
186
188
|
.contentsOfDirectory(atPath: path)
|
|
187
|
-
let ext: String = ".db"
|
|
188
189
|
for file in filenames {
|
|
189
|
-
if
|
|
190
|
-
|
|
190
|
+
if let mExtension = ext {
|
|
191
|
+
if file.hasSuffix(mExtension) {
|
|
192
|
+
files.append(file)
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
if file.prefix(1) != "." {
|
|
196
|
+
files.append(file)
|
|
197
|
+
}
|
|
191
198
|
}
|
|
192
199
|
}
|
|
193
|
-
return
|
|
200
|
+
return files
|
|
194
201
|
} catch let error {
|
|
195
202
|
print("Error: \(error)")
|
|
196
203
|
throw UtilsFileError.getFileListFailed
|
|
@@ -206,7 +213,8 @@ class UtilsFile {
|
|
|
206
213
|
let uTo: URL = databaseURL.appendingPathComponent(toFile)
|
|
207
214
|
let pFrom: String = uFrom.path
|
|
208
215
|
let pTo: String = uTo.path
|
|
209
|
-
let bRet: Bool = try copyFile(pathName: pFrom, toPathName: pTo
|
|
216
|
+
let bRet: Bool = try copyFile(pathName: pFrom, toPathName: pTo,
|
|
217
|
+
overwrite: true)
|
|
210
218
|
if bRet {
|
|
211
219
|
return
|
|
212
220
|
} else {
|
|
@@ -222,7 +230,8 @@ class UtilsFile {
|
|
|
222
230
|
|
|
223
231
|
// MARK: - CopyFromAssetToDatabase
|
|
224
232
|
|
|
225
|
-
class func copyFromAssetToDatabase(fromDb: String, toDb: String
|
|
233
|
+
class func copyFromAssetToDatabase(fromDb: String, toDb: String,
|
|
234
|
+
overwrite: Bool) throws {
|
|
226
235
|
do {
|
|
227
236
|
let uAsset: URL = try getAssetsDatabasesPath()
|
|
228
237
|
.appendingPathComponent(fromDb)
|
|
@@ -230,42 +239,96 @@ class UtilsFile {
|
|
|
230
239
|
let uDb: URL = try getDatabasesUrl()
|
|
231
240
|
.appendingPathComponent(toDb)
|
|
232
241
|
let pDb: String = uDb.path
|
|
233
|
-
let bRet: Bool = try copyFile(pathName: pAsset, toPathName: pDb
|
|
242
|
+
let bRet: Bool = try copyFile(pathName: pAsset, toPathName: pDb,
|
|
243
|
+
overwrite: overwrite)
|
|
234
244
|
if bRet {
|
|
235
245
|
return
|
|
236
246
|
} else {
|
|
237
|
-
|
|
238
|
-
|
|
247
|
+
let msg = "Error: copyFile return false"
|
|
248
|
+
print("\(msg)")
|
|
249
|
+
throw UtilsFileError.copyFromAssetToDatabaseFailed(message: msg)
|
|
239
250
|
}
|
|
240
251
|
} catch UtilsFileError.getAssetsDatabasesPathFailed {
|
|
241
|
-
|
|
242
|
-
|
|
252
|
+
let msg = "Error: getAssetsDatabasesPath Failed"
|
|
253
|
+
print("\(msg)")
|
|
254
|
+
throw UtilsFileError.copyFromAssetToDatabaseFailed(message: msg)
|
|
243
255
|
} catch UtilsFileError.getDatabasesURLFailed {
|
|
244
|
-
|
|
245
|
-
|
|
256
|
+
let msg = "Error: getDatabasesUrl Failed"
|
|
257
|
+
print("\(msg)")
|
|
258
|
+
|
|
259
|
+
throw UtilsFileError.copyFromAssetToDatabaseFailed(message: msg)
|
|
246
260
|
} catch UtilsFileError.copyFileFailed {
|
|
247
|
-
|
|
248
|
-
|
|
261
|
+
let msg = "Error: copyFile Failed"
|
|
262
|
+
print("\(msg)")
|
|
263
|
+
|
|
264
|
+
throw UtilsFileError.copyFromAssetToDatabaseFailed(message: msg)
|
|
249
265
|
} catch let error {
|
|
250
|
-
|
|
251
|
-
|
|
266
|
+
let msg = "Error: \(error)"
|
|
267
|
+
print("\(msg)")
|
|
268
|
+
throw UtilsFileError.copyFromAssetToDatabaseFailed(message: msg)
|
|
252
269
|
}
|
|
253
270
|
|
|
254
271
|
}
|
|
255
272
|
|
|
273
|
+
class func unzipFromAssetToDatabase(zip: String, overwrite: Bool) throws {
|
|
274
|
+
do {
|
|
275
|
+
let zipAsset: URL = try getAssetsDatabasesPath()
|
|
276
|
+
.appendingPathComponent(zip)
|
|
277
|
+
guard let archive = Archive(url: zipAsset, accessMode: .read) else {
|
|
278
|
+
let msg = "Error: Read Archive: \(zipAsset) failed"
|
|
279
|
+
print("\(msg)")
|
|
280
|
+
throw UtilsFileError.unzipFromAssetToDatabaseFailed(message: msg)
|
|
281
|
+
}
|
|
282
|
+
for entry in archive {
|
|
283
|
+
let dbEntry = setPathSuffix(sDb: entry.path)
|
|
284
|
+
let zipCopy: URL = try getDatabasesUrl()
|
|
285
|
+
.appendingPathComponent(dbEntry)
|
|
286
|
+
do {
|
|
287
|
+
let isExist: Bool = isFileExist(filePath: zipCopy.path)
|
|
288
|
+
if !isExist || overwrite {
|
|
289
|
+
if overwrite && isExist {
|
|
290
|
+
_ = try deleteFile(filePath: zipCopy.path)
|
|
291
|
+
}
|
|
292
|
+
_ = try archive.extract(entry, to: zipCopy)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
} catch {
|
|
296
|
+
let msg = "Error: Extracting \(entry.path) from archive failed \(error.localizedDescription)"
|
|
297
|
+
print("\(msg)")
|
|
298
|
+
throw UtilsFileError.unzipFromAssetToDatabaseFailed(message: msg)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
} catch UtilsFileError.getAssetsDatabasesPathFailed {
|
|
302
|
+
let msg = "Error: getAssetsDatabasesPath Failed"
|
|
303
|
+
print("\(msg)")
|
|
304
|
+
throw UtilsFileError.unzipFromAssetToDatabaseFailed(message: msg)
|
|
305
|
+
} catch UtilsFileError.getDatabasesURLFailed {
|
|
306
|
+
let msg = "Error: getDatabasesUrl Failed"
|
|
307
|
+
print("\(msg)")
|
|
308
|
+
throw UtilsFileError.unzipFromAssetToDatabaseFailed(message: msg)
|
|
309
|
+
} catch let error {
|
|
310
|
+
let msg = "Error: \(error)"
|
|
311
|
+
print("\(msg)")
|
|
312
|
+
throw UtilsFileError.unzipFromAssetToDatabaseFailed(message: msg)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
256
316
|
// MARK: - CopyFile
|
|
257
317
|
|
|
258
|
-
class func copyFile(pathName: String, toPathName: String) throws -> Bool {
|
|
318
|
+
class func copyFile(pathName: String, toPathName: String, overwrite: Bool) throws -> Bool {
|
|
259
319
|
if pathName.count > 0 && toPathName.count > 0 {
|
|
260
320
|
let isPath = isFileExist(filePath: pathName)
|
|
261
321
|
if isPath {
|
|
262
322
|
do {
|
|
263
|
-
|
|
264
|
-
|
|
323
|
+
let isExist: Bool = isFileExist(filePath: toPathName)
|
|
324
|
+
if !isExist || overwrite {
|
|
325
|
+
if overwrite && isExist {
|
|
326
|
+
_ = try deleteFile(filePath: toPathName)
|
|
327
|
+
}
|
|
328
|
+
let fileManager = FileManager.default
|
|
329
|
+
try fileManager.copyItem(atPath: pathName,
|
|
330
|
+
toPath: toPathName)
|
|
265
331
|
}
|
|
266
|
-
let fileManager = FileManager.default
|
|
267
|
-
try fileManager.copyItem(atPath: pathName,
|
|
268
|
-
toPath: toPathName)
|
|
269
332
|
return true
|
|
270
333
|
} catch let error {
|
|
271
334
|
print("Error: \(error)")
|
|
@@ -289,7 +352,7 @@ class UtilsFile {
|
|
|
289
352
|
do {
|
|
290
353
|
let fromPath: String = try getFilePath(fileName: fileName)
|
|
291
354
|
let toPath: String = try getFilePath(fileName: toFileName)
|
|
292
|
-
ret = try copyFile(pathName: fromPath, toPathName: toPath)
|
|
355
|
+
ret = try copyFile(pathName: fromPath, toPathName: toPath, overwrite: true)
|
|
293
356
|
return ret
|
|
294
357
|
} catch UtilsFileError.getFilePathFailed {
|
|
295
358
|
print("Error: getFilePath Failed")
|
|
@@ -373,3 +436,4 @@ class UtilsFile {
|
|
|
373
436
|
}
|
|
374
437
|
}
|
|
375
438
|
// swiftlint:enable type_body_length
|
|
439
|
+
// swiftlint:enable file_length
|
|
@@ -14,7 +14,7 @@ enum UtilsMigrateError: Error {
|
|
|
14
14
|
|
|
15
15
|
class UtilsMigrate {
|
|
16
16
|
|
|
17
|
-
// MARK: -
|
|
17
|
+
// MARK: - getMigratableList
|
|
18
18
|
|
|
19
19
|
class func getMigratableList(folderPath: String) throws -> [String] {
|
|
20
20
|
var mDbList: [String] = []
|
|
@@ -25,7 +25,7 @@ class UtilsMigrate {
|
|
|
25
25
|
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
26
26
|
isDirectory: &isDir) &&
|
|
27
27
|
isDir.boolValue {
|
|
28
|
-
mDbList = try UtilsFile.getFileList(path: dbPathURL.relativePath)
|
|
28
|
+
mDbList = try UtilsFile.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
29
29
|
|
|
30
30
|
return mDbList
|
|
31
31
|
} else {
|
|
@@ -47,7 +47,9 @@ class UtilsMigrate {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// MARK: - addSQLiteSuffix
|
|
50
|
+
|
|
50
51
|
// swiftlint:disable function_body_length
|
|
52
|
+
// swiftlint:disable cyclomatic_complexity
|
|
51
53
|
class func addSQLiteSuffix(folderPath: String, dbList: [String]) throws {
|
|
52
54
|
var fromFile: String = ""
|
|
53
55
|
var toFile: String = ""
|
|
@@ -59,12 +61,32 @@ class UtilsMigrate {
|
|
|
59
61
|
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
60
62
|
isDirectory: &isDir) &&
|
|
61
63
|
isDir.boolValue {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
var mDbList: [String]
|
|
65
|
+
if dbList.count > 0 {
|
|
66
|
+
mDbList = try UtilsFile
|
|
67
|
+
.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
68
|
+
} else {
|
|
69
|
+
mDbList = try UtilsFile
|
|
70
|
+
.getFileList(path: dbPathURL.relativePath, ext: "db")
|
|
71
|
+
}
|
|
64
72
|
for file: String in mDbList {
|
|
65
73
|
if !file.contains("SQLite.db") {
|
|
66
74
|
fromFile = file
|
|
67
|
-
if dbList.
|
|
75
|
+
if dbList.count > 0 {
|
|
76
|
+
if dbList.contains(fromFile) {
|
|
77
|
+
if String(file.suffix(3)) == ".db" {
|
|
78
|
+
toFile = file
|
|
79
|
+
.replacingOccurrences(of: ".db", with: "SQLite.db")
|
|
80
|
+
} else {
|
|
81
|
+
toFile = file + "SQLite.db"
|
|
82
|
+
}
|
|
83
|
+
try UtilsFile
|
|
84
|
+
.copyFromNames(dbPathURL: dbPathURL,
|
|
85
|
+
fromFile: fromFile,
|
|
86
|
+
databaseURL: databaseURL,
|
|
87
|
+
toFile: toFile)
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
68
90
|
toFile = file
|
|
69
91
|
.replacingOccurrences(of: ".db", with: "SQLite.db")
|
|
70
92
|
try UtilsFile
|
|
@@ -98,9 +120,13 @@ class UtilsMigrate {
|
|
|
98
120
|
throw UtilsMigrateError.addSQLiteSuffix(message: msg)
|
|
99
121
|
}
|
|
100
122
|
}
|
|
123
|
+
// swiftlint:enable cyclomatic_complexity
|
|
101
124
|
// swiftlint:enable function_body_length
|
|
102
125
|
|
|
103
126
|
// MARK: - deleteOldDatabase
|
|
127
|
+
|
|
128
|
+
// swiftlint:disable function_body_length
|
|
129
|
+
// swiftlint:disable cyclomatic_complexity
|
|
104
130
|
class func deleteOldDatabases(folderPath: String, dbList: [String]) throws {
|
|
105
131
|
do {
|
|
106
132
|
let dbPathURL: URL = try UtilsMigrate
|
|
@@ -109,17 +135,35 @@ class UtilsMigrate {
|
|
|
109
135
|
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
110
136
|
isDirectory: &isDir) &&
|
|
111
137
|
isDir.boolValue {
|
|
112
|
-
|
|
113
|
-
|
|
138
|
+
var mDbList: [String]
|
|
139
|
+
if dbList.count > 0 {
|
|
140
|
+
mDbList = try UtilsFile
|
|
141
|
+
.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
142
|
+
} else {
|
|
143
|
+
mDbList = try UtilsFile
|
|
144
|
+
.getFileList(path: dbPathURL.relativePath, ext: "db")
|
|
145
|
+
}
|
|
114
146
|
for file: String in mDbList {
|
|
115
147
|
if !file.contains("SQLite.db") {
|
|
116
|
-
if dbList.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
if dbList.count > 0 {
|
|
149
|
+
if dbList.contains(file) {
|
|
150
|
+
let ret: Bool = try UtilsFile
|
|
151
|
+
.deleteFile(dbPathURL: dbPathURL, fileName: file)
|
|
152
|
+
if !ret {
|
|
153
|
+
throw UtilsMigrateError
|
|
154
|
+
.deleteOldDatabases(message: "deleteFileFailed")
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
if file.contains(".db") {
|
|
159
|
+
let ret: Bool = try UtilsFile
|
|
160
|
+
.deleteFile(dbPathURL: dbPathURL, fileName: file)
|
|
161
|
+
if !ret {
|
|
162
|
+
throw UtilsMigrateError
|
|
163
|
+
.deleteOldDatabases(message: "deleteFileFailed")
|
|
164
|
+
}
|
|
122
165
|
}
|
|
166
|
+
|
|
123
167
|
}
|
|
124
168
|
}
|
|
125
169
|
}
|
|
@@ -144,6 +188,8 @@ class UtilsMigrate {
|
|
|
144
188
|
throw UtilsMigrateError.addSQLiteSuffix(message: msg)
|
|
145
189
|
}
|
|
146
190
|
}
|
|
191
|
+
// swiftlint:enable cyclomatic_complexity
|
|
192
|
+
// swiftlint:enable function_body_length
|
|
147
193
|
|
|
148
194
|
// MARK: - getFolderURL
|
|
149
195
|
class func getFolderURL(folderPath: String) throws -> URL {
|
|
@@ -100,11 +100,9 @@ class UtilsSecret {
|
|
|
100
100
|
if FileManager.default.fileExists(atPath: databaseURL.relativePath,
|
|
101
101
|
isDirectory: &isDir) && isDir.boolValue {
|
|
102
102
|
let dbList: [String] = try UtilsFile
|
|
103
|
-
.getFileList(path: databaseURL.relativePath)
|
|
103
|
+
.getFileList(path: databaseURL.relativePath, ext: ".db")
|
|
104
104
|
for file: String in dbList {
|
|
105
|
-
print("file: \(file)")
|
|
106
105
|
let state: State = UtilsSQLCipher.getDatabaseState(databaseName: file)
|
|
107
|
-
print("state: \(state)")
|
|
108
106
|
if state.rawValue == "ENCRYPTEDGLOBALSECRET" {
|
|
109
107
|
let globalData: GlobalSQLite = GlobalSQLite()
|
|
110
108
|
let password: String = globalData.secret
|
|
@@ -140,7 +138,6 @@ class UtilsSecret {
|
|
|
140
138
|
|
|
141
139
|
// MARK: - ChangeEncryptionSecret
|
|
142
140
|
|
|
143
|
-
// swiftlint:disable function_body_length
|
|
144
141
|
class func changeEncryptionSecret(passphrase: String, oldPassphrase: String) throws {
|
|
145
142
|
do {
|
|
146
143
|
if passphrase.isEmpty || oldPassphrase.isEmpty {
|
|
@@ -162,11 +159,9 @@ class UtilsSecret {
|
|
|
162
159
|
if FileManager.default.fileExists(atPath: databaseURL.relativePath,
|
|
163
160
|
isDirectory: &isDir) && isDir.boolValue {
|
|
164
161
|
let dbList: [String] = try UtilsFile
|
|
165
|
-
.getFileList(path: databaseURL.relativePath)
|
|
162
|
+
.getFileList(path: databaseURL.relativePath, ext: ".db")
|
|
166
163
|
for file: String in dbList {
|
|
167
|
-
print("file: \(file)")
|
|
168
164
|
let state: State = UtilsSQLCipher.getDatabaseState(databaseName: file)
|
|
169
|
-
print("state: \(state)")
|
|
170
165
|
if state.rawValue == "ENCRYPTEDSECRET" {
|
|
171
166
|
let dbPath: String = try UtilsFile
|
|
172
167
|
.getFilePath(fileName: file)
|
|
@@ -198,6 +193,5 @@ class UtilsSecret {
|
|
|
198
193
|
}
|
|
199
194
|
|
|
200
195
|
}
|
|
201
|
-
// swiftlint:enable function_body_length
|
|
202
196
|
|
|
203
197
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "3.2
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@capacitor/android": "^3.2
|
|
59
|
-
"@capacitor/core": "3.2
|
|
58
|
+
"@capacitor/android": "^3.3.2",
|
|
59
|
+
"@capacitor/core": "3.3.2",
|
|
60
60
|
"@capacitor/docgen": "^0.0.17",
|
|
61
|
-
"@capacitor/ios": "^3.2
|
|
61
|
+
"@capacitor/ios": "^3.3.2",
|
|
62
62
|
"@ionic/eslint-config": "^0.3.0",
|
|
63
63
|
"@ionic/prettier-config": "^1.0.1",
|
|
64
64
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typescript": "~4.0.5"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@capacitor/core": "^3.2
|
|
77
|
+
"@capacitor/core": "^3.3.2"
|
|
78
78
|
},
|
|
79
79
|
"prettier": "@ionic/prettier-config",
|
|
80
80
|
"swiftlint": "@ionic/swiftlint-config",
|