@capacitor-community/sqlite 3.3.1 → 3.3.3-3
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 +49 -0
- package/README.md +27 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +83 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +101 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +24 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +67 -47
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/JsonIndex.java +5 -4
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +9 -0
- 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/UtilsNCDatabase.java +26 -0
- package/dist/esm/definitions.d.ts +111 -2
- package/dist/esm/definitions.js +63 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -1
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +79 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +79 -0
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +17 -1
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +122 -19
- package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +236 -64
- package/ios/Plugin/Database.swift +57 -28
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +2 -1
- package/ios/Plugin/ImportExportJson/JsonSQLite.swift +1 -1
- package/ios/Plugin/ReturnHandler.swift +13 -0
- package/ios/Plugin/SqliteConfig.swift +10 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +10 -7
- package/ios/Plugin/Utils/UtilsFile.swift +207 -38
- package/ios/Plugin/Utils/UtilsMigrate.swift +70 -57
- package/ios/Plugin/Utils/UtilsNCDatabase.swift +31 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +29 -24
- package/ios/Plugin/Utils/UtilsSecret.swift +22 -8
- package/ios/Plugin/Utils/UtilsUpgrade.swift +6 -2
- package/package.json +5 -5
|
@@ -9,23 +9,22 @@ enum UtilsMigrateError: Error {
|
|
|
9
9
|
case addSQLiteSuffix(message: String)
|
|
10
10
|
case getMigratableList(message: String)
|
|
11
11
|
case deleteOldDatabases(message: String)
|
|
12
|
-
case getFolderURL(message: String)
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
class UtilsMigrate {
|
|
16
15
|
|
|
17
|
-
// MARK: -
|
|
16
|
+
// MARK: - getMigratableList
|
|
18
17
|
|
|
19
18
|
class func getMigratableList(folderPath: String) throws -> [String] {
|
|
20
19
|
var mDbList: [String] = []
|
|
21
20
|
do {
|
|
22
|
-
let dbPathURL: URL = try
|
|
21
|
+
let dbPathURL: URL = try UtilsFile
|
|
23
22
|
.getFolderURL(folderPath: folderPath)
|
|
24
23
|
var isDir = ObjCBool(true)
|
|
25
24
|
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
26
25
|
isDirectory: &isDir) &&
|
|
27
26
|
isDir.boolValue {
|
|
28
|
-
mDbList = try UtilsFile.getFileList(path: dbPathURL.relativePath, ext:
|
|
27
|
+
mDbList = try UtilsFile.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
29
28
|
|
|
30
29
|
return mDbList
|
|
31
30
|
} else {
|
|
@@ -34,9 +33,9 @@ class UtilsMigrate {
|
|
|
34
33
|
throw UtilsMigrateError.getMigratableList(message: msg)
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
} catch UtilsFileError.
|
|
36
|
+
} catch UtilsFileError.getFolderURLFailed {
|
|
38
37
|
throw UtilsMigrateError
|
|
39
|
-
.getMigratableList(message: "
|
|
38
|
+
.getMigratableList(message: "getFolderURLFailed")
|
|
40
39
|
} catch UtilsFileError.getFileListFailed {
|
|
41
40
|
throw UtilsMigrateError.getMigratableList(message: "getFileListFailed")
|
|
42
41
|
} catch let error {
|
|
@@ -47,24 +46,48 @@ class UtilsMigrate {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
// MARK: - addSQLiteSuffix
|
|
49
|
+
|
|
50
50
|
// swiftlint:disable function_body_length
|
|
51
|
-
|
|
51
|
+
// swiftlint:disable cyclomatic_complexity
|
|
52
|
+
class func addSQLiteSuffix(databaseLocation: String, folderPath: String,
|
|
53
|
+
dbList: [String]) throws {
|
|
52
54
|
var fromFile: String = ""
|
|
53
55
|
var toFile: String = ""
|
|
54
56
|
do {
|
|
55
|
-
let databaseURL = try UtilsFile
|
|
56
|
-
|
|
57
|
+
let databaseURL: URL = try UtilsFile
|
|
58
|
+
.getFolderURL(folderPath: databaseLocation)
|
|
59
|
+
let dbPathURL: URL = try UtilsFile
|
|
57
60
|
.getFolderURL(folderPath: folderPath)
|
|
58
61
|
var isDir = ObjCBool(true)
|
|
59
62
|
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
60
63
|
isDirectory: &isDir) &&
|
|
61
64
|
isDir.boolValue {
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
var mDbList: [String]
|
|
66
|
+
if dbList.count > 0 {
|
|
67
|
+
mDbList = try UtilsFile
|
|
68
|
+
.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
69
|
+
} else {
|
|
70
|
+
mDbList = try UtilsFile
|
|
71
|
+
.getFileList(path: dbPathURL.relativePath, ext: "db")
|
|
72
|
+
}
|
|
64
73
|
for file: String in mDbList {
|
|
65
74
|
if !file.contains("SQLite.db") {
|
|
66
75
|
fromFile = file
|
|
67
|
-
if dbList.
|
|
76
|
+
if dbList.count > 0 {
|
|
77
|
+
if dbList.contains(fromFile) {
|
|
78
|
+
if String(file.suffix(3)) == ".db" {
|
|
79
|
+
toFile = file
|
|
80
|
+
.replacingOccurrences(of: ".db", with: "SQLite.db")
|
|
81
|
+
} else {
|
|
82
|
+
toFile = file + "SQLite.db"
|
|
83
|
+
}
|
|
84
|
+
try UtilsFile
|
|
85
|
+
.copyFromNames(dbPathURL: dbPathURL,
|
|
86
|
+
fromFile: fromFile,
|
|
87
|
+
databaseURL: databaseURL,
|
|
88
|
+
toFile: toFile)
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
68
91
|
toFile = file
|
|
69
92
|
.replacingOccurrences(of: ".db", with: "SQLite.db")
|
|
70
93
|
try UtilsFile
|
|
@@ -84,7 +107,7 @@ class UtilsMigrate {
|
|
|
84
107
|
} catch UtilsFileError.getDatabasesURLFailed {
|
|
85
108
|
throw UtilsMigrateError
|
|
86
109
|
.addSQLiteSuffix(message: "getDatabasesURLFailed")
|
|
87
|
-
} catch
|
|
110
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
88
111
|
throw UtilsMigrateError.addSQLiteSuffix(message: message)
|
|
89
112
|
} catch UtilsFileError.getFileListFailed {
|
|
90
113
|
throw UtilsMigrateError.addSQLiteSuffix(message: "getFileListFailed")
|
|
@@ -98,28 +121,50 @@ class UtilsMigrate {
|
|
|
98
121
|
throw UtilsMigrateError.addSQLiteSuffix(message: msg)
|
|
99
122
|
}
|
|
100
123
|
}
|
|
124
|
+
// swiftlint:enable cyclomatic_complexity
|
|
101
125
|
// swiftlint:enable function_body_length
|
|
102
126
|
|
|
103
127
|
// MARK: - deleteOldDatabase
|
|
128
|
+
|
|
129
|
+
// swiftlint:disable function_body_length
|
|
130
|
+
// swiftlint:disable cyclomatic_complexity
|
|
104
131
|
class func deleteOldDatabases(folderPath: String, dbList: [String]) throws {
|
|
105
132
|
do {
|
|
106
|
-
let dbPathURL: URL = try
|
|
133
|
+
let dbPathURL: URL = try UtilsFile
|
|
107
134
|
.getFolderURL(folderPath: folderPath)
|
|
108
135
|
var isDir = ObjCBool(true)
|
|
109
136
|
if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
|
|
110
137
|
isDirectory: &isDir) &&
|
|
111
138
|
isDir.boolValue {
|
|
112
|
-
|
|
113
|
-
|
|
139
|
+
var mDbList: [String]
|
|
140
|
+
if dbList.count > 0 {
|
|
141
|
+
mDbList = try UtilsFile
|
|
142
|
+
.getFileList(path: dbPathURL.relativePath, ext: nil)
|
|
143
|
+
} else {
|
|
144
|
+
mDbList = try UtilsFile
|
|
145
|
+
.getFileList(path: dbPathURL.relativePath, ext: "db")
|
|
146
|
+
}
|
|
114
147
|
for file: String in mDbList {
|
|
115
148
|
if !file.contains("SQLite.db") {
|
|
116
|
-
if dbList.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
if dbList.count > 0 {
|
|
150
|
+
if dbList.contains(file) {
|
|
151
|
+
let ret: Bool = try UtilsFile
|
|
152
|
+
.deleteFile(dbPathURL: dbPathURL, fileName: file)
|
|
153
|
+
if !ret {
|
|
154
|
+
throw UtilsMigrateError
|
|
155
|
+
.deleteOldDatabases(message: "deleteFileFailed")
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
if file.contains(".db") {
|
|
160
|
+
let ret: Bool = try UtilsFile
|
|
161
|
+
.deleteFile(dbPathURL: dbPathURL, fileName: file)
|
|
162
|
+
if !ret {
|
|
163
|
+
throw UtilsMigrateError
|
|
164
|
+
.deleteOldDatabases(message: "deleteFileFailed")
|
|
165
|
+
}
|
|
122
166
|
}
|
|
167
|
+
|
|
123
168
|
}
|
|
124
169
|
}
|
|
125
170
|
}
|
|
@@ -132,7 +177,7 @@ class UtilsMigrate {
|
|
|
132
177
|
} catch UtilsFileError.getDatabasesURLFailed {
|
|
133
178
|
throw UtilsMigrateError
|
|
134
179
|
.addSQLiteSuffix(message: "getDatabasesURLFailed")
|
|
135
|
-
} catch
|
|
180
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
136
181
|
throw UtilsMigrateError.addSQLiteSuffix(message: message)
|
|
137
182
|
} catch UtilsFileError.getFileListFailed {
|
|
138
183
|
throw UtilsMigrateError.addSQLiteSuffix(message: "getFileListFailed")
|
|
@@ -144,39 +189,7 @@ class UtilsMigrate {
|
|
|
144
189
|
throw UtilsMigrateError.addSQLiteSuffix(message: msg)
|
|
145
190
|
}
|
|
146
191
|
}
|
|
147
|
-
|
|
148
|
-
//
|
|
149
|
-
class func getFolderURL(folderPath: String) throws -> URL {
|
|
150
|
-
do {
|
|
151
|
-
let databaseURL = try UtilsFile.getDatabasesUrl().absoluteURL
|
|
152
|
-
var dbPathURL: URL
|
|
153
|
-
let first = folderPath.split(separator: "/", maxSplits: 1)
|
|
154
|
-
if first[0] == "Applications" {
|
|
155
|
-
dbPathURL = try UtilsFile.getApplicationURL().absoluteURL
|
|
156
|
-
} else if first[0] == "Library" {
|
|
157
|
-
dbPathURL = try UtilsFile.getLibraryURL().absoluteURL
|
|
158
|
-
} else if first[0] == "Documents" || first[0] == "default" {
|
|
159
|
-
dbPathURL = databaseURL
|
|
160
|
-
} else {
|
|
161
|
-
var msg: String = "addSQLiteSuffix command failed :"
|
|
162
|
-
msg.append(" Folder '\(first[0])' not allowed")
|
|
163
|
-
throw UtilsMigrateError.getFolderURL(message: msg)
|
|
164
|
-
}
|
|
165
|
-
if first.count > 1 {
|
|
166
|
-
dbPathURL = dbPathURL
|
|
167
|
-
.appendingPathComponent(String(first[1])).absoluteURL
|
|
168
|
-
}
|
|
169
|
-
return dbPathURL
|
|
170
|
-
} catch UtilsFileError.getDatabasesURLFailed {
|
|
171
|
-
throw UtilsMigrateError.getFolderURL(message: "getDatabasesURLFailed")
|
|
172
|
-
} catch UtilsFileError.getApplicationURLFailed {
|
|
173
|
-
throw UtilsMigrateError
|
|
174
|
-
.getFolderURL(message: "getApplicationURLFailed")
|
|
175
|
-
} catch let error {
|
|
176
|
-
var msg: String = "getFolderURL command failed :"
|
|
177
|
-
msg.append(" \(error.localizedDescription)")
|
|
178
|
-
throw UtilsMigrateError.getFolderURL(message: msg)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
192
|
+
// swiftlint:enable cyclomatic_complexity
|
|
193
|
+
// swiftlint:enable function_body_length
|
|
181
194
|
|
|
182
195
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// UtilsNCDatabase.swift
|
|
3
|
+
// CapacitorCommunitySqlite
|
|
4
|
+
//
|
|
5
|
+
// Created by Quéau Jean Pierre on 17/12/2021.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
enum UtilsNCDatabaseError: Error {
|
|
10
|
+
case getNCDatabasePath(message: String)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class UtilsNCDatabase {
|
|
14
|
+
|
|
15
|
+
// MARK: - getNCDatabasePath
|
|
16
|
+
|
|
17
|
+
class func getNCDatabasePath(folderPath: String, database: String) throws -> String {
|
|
18
|
+
do {
|
|
19
|
+
let dbPathURL: URL = try UtilsFile
|
|
20
|
+
.getFolderURL(folderPath: folderPath)
|
|
21
|
+
return dbPathURL.appendingPathComponent("\(database)").path
|
|
22
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
23
|
+
throw UtilsNCDatabaseError.getNCDatabasePath(message: message)
|
|
24
|
+
} catch let error {
|
|
25
|
+
var msg: String = "getNCDatabasePath command failed :"
|
|
26
|
+
msg.append(" \(error.localizedDescription)")
|
|
27
|
+
throw UtilsNCDatabaseError.getNCDatabasePath(message: msg)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -43,9 +43,12 @@ enum State: String {
|
|
|
43
43
|
// swiftlint:disable type_body_length
|
|
44
44
|
class UtilsSQLCipher {
|
|
45
45
|
|
|
46
|
-
class func getDatabaseState(
|
|
46
|
+
class func getDatabaseState(databaseLocation: String,
|
|
47
|
+
databaseName: String) -> State {
|
|
47
48
|
do {
|
|
48
|
-
let path: String = try UtilsFile
|
|
49
|
+
let path: String = try UtilsFile
|
|
50
|
+
.getFilePath(databaseLocation: databaseLocation,
|
|
51
|
+
fileName: databaseName)
|
|
49
52
|
if UtilsFile.isFileExist(filePath: path) {
|
|
50
53
|
do {
|
|
51
54
|
try openDBNoPassword(dBPath: path)
|
|
@@ -586,17 +589,17 @@ class UtilsSQLCipher {
|
|
|
586
589
|
|
|
587
590
|
// MARK: - DeleteDB
|
|
588
591
|
|
|
589
|
-
class func deleteDB(databaseName: String) throws {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
592
|
+
class func deleteDB(databaseLocation: String, databaseName: String) throws {
|
|
593
|
+
do {
|
|
594
|
+
let dir: URL = try UtilsFile
|
|
595
|
+
.getFolderURL(folderPath: databaseLocation)
|
|
596
|
+
|
|
593
597
|
let fileURL = dir.appendingPathComponent(databaseName)
|
|
594
598
|
let isFileExists = FileManager.default.fileExists(
|
|
595
599
|
atPath: fileURL.path)
|
|
596
600
|
if isFileExists {
|
|
597
601
|
do {
|
|
598
602
|
try FileManager.default.removeItem(at: fileURL)
|
|
599
|
-
print("Database \(databaseName) deleted")
|
|
600
603
|
} catch let error {
|
|
601
604
|
var msg: String = "Error: deleteDB: "
|
|
602
605
|
msg.append(" \(error.localizedDescription)")
|
|
@@ -604,6 +607,9 @@ class UtilsSQLCipher {
|
|
|
604
607
|
message: msg)
|
|
605
608
|
}
|
|
606
609
|
}
|
|
610
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
611
|
+
let msg = "Error: deleteDB: \(message)"
|
|
612
|
+
throw UtilsSQLCipherError.deleteDB(message: msg)
|
|
607
613
|
}
|
|
608
614
|
}
|
|
609
615
|
|
|
@@ -663,10 +669,11 @@ class UtilsSQLCipher {
|
|
|
663
669
|
|
|
664
670
|
// MARK: - RestoreDB
|
|
665
671
|
|
|
666
|
-
class func restoreDB(databaseName: String) throws {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
672
|
+
class func restoreDB(databaseLocation: String, databaseName: String) throws {
|
|
673
|
+
do {
|
|
674
|
+
let dir: URL = try UtilsFile
|
|
675
|
+
.getFolderURL(folderPath: databaseLocation)
|
|
676
|
+
|
|
670
677
|
let fileURL = dir.appendingPathComponent(databaseName)
|
|
671
678
|
let backupURL = dir
|
|
672
679
|
.appendingPathComponent("backup-\(databaseName)")
|
|
@@ -678,13 +685,11 @@ class UtilsSQLCipher {
|
|
|
678
685
|
if isFileExists {
|
|
679
686
|
do {
|
|
680
687
|
try FileManager.default.removeItem(at: fileURL)
|
|
681
|
-
print("Database \(databaseName) deleted")
|
|
682
688
|
try FileManager
|
|
683
689
|
.default.copyItem(atPath: backupURL.path,
|
|
684
690
|
toPath: fileURL.path)
|
|
685
691
|
try FileManager.default
|
|
686
692
|
.removeItem(at: backupURL)
|
|
687
|
-
print("Database backup-\(databaseName) deleted")
|
|
688
693
|
} catch {
|
|
689
694
|
var msg = "Error: restoreDB : \(databaseName)"
|
|
690
695
|
msg += " \(error)"
|
|
@@ -704,19 +709,20 @@ class UtilsSQLCipher {
|
|
|
704
709
|
throw UtilsSQLCipherError.restoreDB(
|
|
705
710
|
message: msg)
|
|
706
711
|
}
|
|
707
|
-
}
|
|
708
|
-
let msg = "Error: restoreDB:
|
|
709
|
-
throw UtilsSQLCipherError.restoreDB(
|
|
710
|
-
message: msg)
|
|
712
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
713
|
+
let msg = "Error: restoreDB: \(message)"
|
|
714
|
+
throw UtilsSQLCipherError.restoreDB(message: msg)
|
|
711
715
|
}
|
|
712
716
|
}
|
|
713
717
|
|
|
714
718
|
// MARK: - deleteBackupDB
|
|
715
719
|
|
|
716
|
-
class func deleteBackupDB(
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
+
class func deleteBackupDB(databaseLocation: String,
|
|
721
|
+
databaseName: String) throws {
|
|
722
|
+
|
|
723
|
+
do {
|
|
724
|
+
let dir: URL = try UtilsFile
|
|
725
|
+
.getFolderURL(folderPath: databaseLocation)
|
|
720
726
|
let backupURL = dir
|
|
721
727
|
.appendingPathComponent("backup-\(databaseName)")
|
|
722
728
|
let isBackupExists = FileManager.default.fileExists(
|
|
@@ -725,7 +731,6 @@ class UtilsSQLCipher {
|
|
|
725
731
|
do {
|
|
726
732
|
try FileManager.default
|
|
727
733
|
.removeItem(at: backupURL)
|
|
728
|
-
print("Database backup-\(databaseName) deleted")
|
|
729
734
|
} catch {
|
|
730
735
|
var msg = "Error: deleteBackupDB : \(databaseName)"
|
|
731
736
|
msg += " \(error)"
|
|
@@ -737,8 +742,8 @@ class UtilsSQLCipher {
|
|
|
737
742
|
msg.append("backup-\(databaseName) does not exist")
|
|
738
743
|
throw UtilsSQLCipherError.deleteBackupDB(message: msg)
|
|
739
744
|
}
|
|
740
|
-
}
|
|
741
|
-
let msg = "Error: deleteBackupDB:
|
|
745
|
+
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
746
|
+
let msg = "Error: deleteBackupDB: \(message)"
|
|
742
747
|
throw UtilsSQLCipherError.deleteBackupDB(
|
|
743
748
|
message: msg)
|
|
744
749
|
}
|
|
@@ -85,7 +85,9 @@ class UtilsSecret {
|
|
|
85
85
|
|
|
86
86
|
// MARK: - SetEncryptionSecret
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
// swiftlint:disable function_body_length
|
|
89
|
+
class func setEncryptionSecret(passphrase: String,
|
|
90
|
+
databaseLocation: String) throws {
|
|
89
91
|
do {
|
|
90
92
|
if passphrase.isEmpty {
|
|
91
93
|
let msg: String = "passphrase must not be empty"
|
|
@@ -102,13 +104,16 @@ class UtilsSecret {
|
|
|
102
104
|
let dbList: [String] = try UtilsFile
|
|
103
105
|
.getFileList(path: databaseURL.relativePath, ext: ".db")
|
|
104
106
|
for file: String in dbList {
|
|
105
|
-
let state: State = UtilsSQLCipher
|
|
107
|
+
let state: State = UtilsSQLCipher
|
|
108
|
+
.getDatabaseState(databaseLocation: databaseLocation,
|
|
109
|
+
databaseName: file)
|
|
106
110
|
if state.rawValue == "ENCRYPTEDGLOBALSECRET" {
|
|
107
111
|
let globalData: GlobalSQLite = GlobalSQLite()
|
|
108
112
|
let password: String = globalData.secret
|
|
109
113
|
|
|
110
114
|
let dbPath: String = try UtilsFile
|
|
111
|
-
.getFilePath(
|
|
115
|
+
.getFilePath(databaseLocation: databaseLocation,
|
|
116
|
+
fileName: file)
|
|
112
117
|
try UtilsSQLCipher.changePassword(filename: dbPath,
|
|
113
118
|
password: password,
|
|
114
119
|
newpassword: passphrase)
|
|
@@ -135,10 +140,14 @@ class UtilsSecret {
|
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
}
|
|
143
|
+
// swiftlint:enable function_body_length
|
|
138
144
|
|
|
139
145
|
// MARK: - ChangeEncryptionSecret
|
|
140
146
|
|
|
141
|
-
|
|
147
|
+
// swiftlint:disable function_body_length
|
|
148
|
+
class func changeEncryptionSecret(passphrase: String,
|
|
149
|
+
oldPassphrase: String,
|
|
150
|
+
databaseLocation: String) throws {
|
|
142
151
|
do {
|
|
143
152
|
if passphrase.isEmpty || oldPassphrase.isEmpty {
|
|
144
153
|
let msg: String = "Passphrase and/or oldpassphrase must not " +
|
|
@@ -153,18 +162,22 @@ class UtilsSecret {
|
|
|
153
162
|
let msg: String = "Given oldpassphrase is wrong"
|
|
154
163
|
throw UtilsSecretError.changeEncryptionSecret(message: msg)
|
|
155
164
|
}
|
|
156
|
-
// get the list of databases
|
|
157
|
-
let databaseURL: URL = try UtilsFile
|
|
165
|
+
// get the list of databases from the database folder
|
|
166
|
+
let databaseURL: URL = try UtilsFile
|
|
167
|
+
.getFolderURL(folderPath: databaseLocation).absoluteURL
|
|
158
168
|
var isDir = ObjCBool(true)
|
|
159
169
|
if FileManager.default.fileExists(atPath: databaseURL.relativePath,
|
|
160
170
|
isDirectory: &isDir) && isDir.boolValue {
|
|
161
171
|
let dbList: [String] = try UtilsFile
|
|
162
172
|
.getFileList(path: databaseURL.relativePath, ext: ".db")
|
|
163
173
|
for file: String in dbList {
|
|
164
|
-
let state: State = UtilsSQLCipher
|
|
174
|
+
let state: State = UtilsSQLCipher
|
|
175
|
+
.getDatabaseState(databaseLocation: databaseLocation,
|
|
176
|
+
databaseName: file)
|
|
165
177
|
if state.rawValue == "ENCRYPTEDSECRET" {
|
|
166
178
|
let dbPath: String = try UtilsFile
|
|
167
|
-
.getFilePath(
|
|
179
|
+
.getFilePath(databaseLocation: databaseLocation,
|
|
180
|
+
fileName: file)
|
|
168
181
|
try UtilsSQLCipher.changePassword(filename: dbPath,
|
|
169
182
|
password: oldPassphrase,
|
|
170
183
|
newpassword: passphrase)
|
|
@@ -193,5 +206,6 @@ class UtilsSecret {
|
|
|
193
206
|
}
|
|
194
207
|
|
|
195
208
|
}
|
|
209
|
+
// swiftlint:enable function_body_length
|
|
196
210
|
|
|
197
211
|
}
|
|
@@ -33,10 +33,12 @@ class UtilsUpgrade {
|
|
|
33
33
|
|
|
34
34
|
// swiftlint:disable cyclomatic_complexity
|
|
35
35
|
// swiftlint:disable function_body_length
|
|
36
|
+
// swiftlint:disable function_parameter_count
|
|
36
37
|
func onUpgrade(mDB: Database,
|
|
37
38
|
upgDict: [Int: [String: Any]],
|
|
38
39
|
dbName: String, currentVersion: Int,
|
|
39
|
-
targetVersion: Int
|
|
40
|
+
targetVersion: Int,
|
|
41
|
+
databaseLocation: String) throws -> Int {
|
|
40
42
|
|
|
41
43
|
var changes: Int = -1
|
|
42
44
|
guard let upgrade: [String: Any] = upgDict[currentVersion]
|
|
@@ -76,7 +78,8 @@ class UtilsUpgrade {
|
|
|
76
78
|
toggle: false)
|
|
77
79
|
// backup the database
|
|
78
80
|
_ = try UtilsFile.copyFile(fileName: dbName,
|
|
79
|
-
toFileName: "backup-\(dbName)"
|
|
81
|
+
toFileName: "backup-\(dbName)",
|
|
82
|
+
databaseLocation: databaseLocation)
|
|
80
83
|
|
|
81
84
|
let initChanges = UtilsSQLCipher.dbChanges(mDB: mDB.mDb)
|
|
82
85
|
|
|
@@ -121,6 +124,7 @@ class UtilsUpgrade {
|
|
|
121
124
|
message: message)
|
|
122
125
|
}
|
|
123
126
|
}
|
|
127
|
+
// swiftlint:enable function_parameter_count
|
|
124
128
|
// swiftlint:enable function_body_length
|
|
125
129
|
// swiftlint:enable cyclomatic_complexity
|
|
126
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3-3",
|
|
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.3.
|
|
59
|
-
"@capacitor/core": "3.3.
|
|
58
|
+
"@capacitor/android": "^3.3.3",
|
|
59
|
+
"@capacitor/core": "3.3.3",
|
|
60
60
|
"@capacitor/docgen": "^0.0.17",
|
|
61
|
-
"@capacitor/ios": "^3.3.
|
|
61
|
+
"@capacitor/ios": "^3.3.3",
|
|
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.3.
|
|
77
|
+
"@capacitor/core": "^3.3.3"
|
|
78
78
|
},
|
|
79
79
|
"prettier": "@ionic/prettier-config",
|
|
80
80
|
"swiftlint": "@ionic/swiftlint-config",
|