@capacitor-community/sqlite 3.3.3-1 → 3.3.3-5
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 +40 -0
- package/README.md +22 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +22 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +25 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/RetHandler.java +25 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +10 -1
- package/dist/esm/definitions.d.ts +20 -0
- package/dist/esm/definitions.js +11 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +14 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +14 -0
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +3 -0
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +738 -552
- package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +166 -72
- package/ios/Plugin/Database.swift +29 -11
- package/ios/Plugin/ReturnHandler.swift +12 -0
- package/ios/Plugin/SqliteConfig.swift +10 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +10 -7
- package/ios/Plugin/Utils/UtilsFile.swift +194 -33
- package/ios/Plugin/Utils/UtilsMigrate.swift +11 -44
- package/ios/Plugin/Utils/UtilsNCDatabase.swift +2 -2
- 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 +1 -1
|
@@ -5,7 +5,33 @@ enum CapacitorSQLiteError: Error {
|
|
|
5
5
|
// swiftlint:disable file_length
|
|
6
6
|
// swiftlint:disable type_body_length
|
|
7
7
|
@objc public class CapacitorSQLite: NSObject {
|
|
8
|
+
private var config: SqliteConfig
|
|
8
9
|
private var dbDict: [String: Database] = [:]
|
|
10
|
+
private var databaseLocation: String
|
|
11
|
+
private var initMessage: String = ""
|
|
12
|
+
private var isInit: Bool = false
|
|
13
|
+
|
|
14
|
+
init(config: SqliteConfig) {
|
|
15
|
+
self.config = config
|
|
16
|
+
if let isLocation = config.iosDatabaseLocation {
|
|
17
|
+
self.databaseLocation = isLocation
|
|
18
|
+
// create the databaseLocation directory
|
|
19
|
+
do {
|
|
20
|
+
try UtilsFile.createDatabaseLocation(location: isLocation)
|
|
21
|
+
isInit = true
|
|
22
|
+
} catch UtilsFileError.createDatabaseLocationFailed(let message) {
|
|
23
|
+
initMessage = message
|
|
24
|
+
} catch let error {
|
|
25
|
+
initMessage = "Init Plugin failed :"
|
|
26
|
+
initMessage.append(" \(error.localizedDescription)")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} else {
|
|
30
|
+
self.databaseLocation = "Documents"
|
|
31
|
+
isInit = true
|
|
32
|
+
}
|
|
33
|
+
super.init()
|
|
34
|
+
}
|
|
9
35
|
|
|
10
36
|
// MARK: - Echo
|
|
11
37
|
|
|
@@ -16,27 +42,37 @@ enum CapacitorSQLiteError: Error {
|
|
|
16
42
|
// MARK: - IsSecretStored
|
|
17
43
|
|
|
18
44
|
@objc public func isSecretStored() throws -> NSNumber {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
45
|
+
if isInit {
|
|
46
|
+
let isSecretExists: Bool = UtilsSecret.isPassphrase()
|
|
47
|
+
if isSecretExists {
|
|
48
|
+
return 1
|
|
49
|
+
} else {
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
22
52
|
} else {
|
|
23
|
-
|
|
53
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
24
54
|
}
|
|
25
55
|
}
|
|
26
56
|
|
|
27
57
|
// MARK: - SetEncryptionSecret
|
|
28
58
|
|
|
29
59
|
@objc public func setEncryptionSecret(passphrase: String) throws {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
if isInit {
|
|
61
|
+
do {
|
|
62
|
+
// close all connections
|
|
63
|
+
try closeAllConnections()
|
|
64
|
+
// set encryption secret
|
|
65
|
+
try UtilsSecret
|
|
66
|
+
.setEncryptionSecret(passphrase: passphrase,
|
|
67
|
+
databaseLocation: databaseLocation)
|
|
68
|
+
return
|
|
69
|
+
} catch UtilsSecretError.setEncryptionSecret(let message) {
|
|
70
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
71
|
+
} catch let error {
|
|
72
|
+
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
40
76
|
}
|
|
41
77
|
}
|
|
42
78
|
|
|
@@ -44,79 +80,98 @@ enum CapacitorSQLiteError: Error {
|
|
|
44
80
|
|
|
45
81
|
@objc public func changeEncryptionSecret(passphrase: String,
|
|
46
82
|
oldPassphrase: String) throws {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
83
|
+
if isInit {
|
|
84
|
+
do {
|
|
85
|
+
// close all connections
|
|
86
|
+
try closeAllConnections()
|
|
87
|
+
// set encryption secret
|
|
88
|
+
try UtilsSecret
|
|
89
|
+
.changeEncryptionSecret(passphrase: passphrase,
|
|
90
|
+
oldPassphrase: oldPassphrase,
|
|
91
|
+
databaseLocation: databaseLocation)
|
|
92
|
+
return
|
|
93
|
+
} catch UtilsSecretError.changeEncryptionSecret(let message) {
|
|
94
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
95
|
+
} catch let error {
|
|
96
|
+
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
57
100
|
}
|
|
58
101
|
|
|
59
102
|
}
|
|
60
103
|
// MARK: - getNCDatabasePath
|
|
61
104
|
|
|
62
105
|
@objc public func getNCDatabasePath(_ folderPath: String, dbName: String ) throws -> String {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
106
|
+
if isInit {
|
|
107
|
+
do {
|
|
108
|
+
let databasePath: String = try UtilsNCDatabase
|
|
109
|
+
.getNCDatabasePath(folderPath: folderPath,
|
|
110
|
+
database: dbName )
|
|
111
|
+
return databasePath
|
|
112
|
+
} catch let error {
|
|
113
|
+
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
70
117
|
}
|
|
71
|
-
|
|
72
118
|
}
|
|
73
119
|
|
|
74
120
|
// MARK: - CreateNCConnection
|
|
75
121
|
|
|
76
122
|
@objc public func createNCConnection(_ databasePath: String,
|
|
77
123
|
version: Int) throws {
|
|
124
|
+
if isInit {
|
|
78
125
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
126
|
+
// check if the connection already exists
|
|
127
|
+
let conn = dbDict[databasePath]
|
|
128
|
+
if conn != nil {
|
|
129
|
+
let msg = "Connection \(databasePath) already exists"
|
|
130
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
131
|
+
}
|
|
85
132
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
133
|
+
do {
|
|
134
|
+
let isFileExists: Bool = UtilsFile
|
|
135
|
+
.isFileExist(filePath: databasePath)
|
|
89
136
|
|
|
90
|
-
|
|
91
|
-
|
|
137
|
+
if !isFileExists {
|
|
138
|
+
throw CapacitorSQLiteError.failed(message: "database \(databasePath) does not exist")
|
|
139
|
+
}
|
|
140
|
+
let mDb: Database = try Database(
|
|
141
|
+
databaseLocation: databaseLocation,
|
|
142
|
+
databaseName: databasePath,
|
|
143
|
+
encrypted: false, mode: "no-encryption", version: version,
|
|
144
|
+
vUpgDict: [:])
|
|
145
|
+
dbDict[databasePath] = mDb
|
|
146
|
+
return
|
|
147
|
+
} catch let error {
|
|
148
|
+
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
92
149
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
encrypted: false, mode: "no-encryption", version: version,
|
|
96
|
-
vUpgDict: [:])
|
|
97
|
-
dbDict[databasePath] = mDb
|
|
98
|
-
return
|
|
99
|
-
} catch let error {
|
|
100
|
-
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
150
|
+
} else {
|
|
151
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
101
152
|
}
|
|
102
153
|
}
|
|
103
154
|
|
|
104
155
|
// MARK: - CloseNCConnection
|
|
105
156
|
|
|
106
157
|
@objc public func closeNCConnection(_ dbName: String) throws {
|
|
107
|
-
|
|
108
|
-
let
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
158
|
+
if isInit {
|
|
159
|
+
guard let mDb: Database = dbDict[dbName] else {
|
|
160
|
+
let msg = "Connection to \(dbName) not available"
|
|
161
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
162
|
+
}
|
|
163
|
+
if mDb.isDBOpen() {
|
|
164
|
+
do {
|
|
165
|
+
try mDb.close()
|
|
166
|
+
} catch DatabaseError.close(let message) {
|
|
167
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
168
|
+
}
|
|
116
169
|
}
|
|
170
|
+
dbDict.removeValue(forKey: dbName)
|
|
171
|
+
return
|
|
172
|
+
} else {
|
|
173
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
117
174
|
}
|
|
118
|
-
dbDict.removeValue(forKey: dbName)
|
|
119
|
-
return
|
|
120
175
|
}
|
|
121
176
|
|
|
122
177
|
// MARK: - CreateConnection
|
|
@@ -126,186 +181,240 @@ enum CapacitorSQLiteError: Error {
|
|
|
126
181
|
mode: String,
|
|
127
182
|
version: Int,
|
|
128
183
|
vUpgDict: [Int: [String: Any]]) throws {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
184
|
+
if isInit {
|
|
185
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
186
|
+
// check if the connection already exists
|
|
187
|
+
let conn = dbDict[mDbName]
|
|
188
|
+
if conn != nil {
|
|
189
|
+
let msg = "Connection \(mDbName) already exists"
|
|
190
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
do {
|
|
194
|
+
let mDb: Database = try Database(
|
|
195
|
+
databaseLocation: databaseLocation,
|
|
196
|
+
databaseName: "\(mDbName)SQLite.db",
|
|
197
|
+
encrypted: encrypted, mode: mode, version: version,
|
|
198
|
+
vUpgDict: vUpgDict)
|
|
199
|
+
dbDict[mDbName] = mDb
|
|
200
|
+
return
|
|
201
|
+
} catch let error {
|
|
202
|
+
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
146
206
|
}
|
|
147
207
|
}
|
|
148
208
|
|
|
149
209
|
// MARK: - Open
|
|
150
210
|
|
|
151
211
|
@objc public func open(_ dbName: String) throws {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
212
|
+
if isInit {
|
|
213
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
214
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
215
|
+
let msg = "Connection to \(mDbName) not available"
|
|
216
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
217
|
+
}
|
|
218
|
+
do {
|
|
219
|
+
try mDb.open()
|
|
220
|
+
return
|
|
221
|
+
} catch DatabaseError.open(let message) {
|
|
222
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
162
226
|
}
|
|
163
227
|
}
|
|
164
228
|
|
|
165
229
|
// MARK: - Close
|
|
166
230
|
|
|
167
231
|
@objc public func close(_ dbName: String) throws {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
let
|
|
171
|
-
|
|
232
|
+
if isInit {
|
|
233
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
234
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
235
|
+
let msg = "Connection to \(mDbName) not available"
|
|
236
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
237
|
+
}
|
|
238
|
+
do {
|
|
239
|
+
try mDb.close()
|
|
240
|
+
return
|
|
241
|
+
} catch DatabaseError.close(let message) {
|
|
242
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
172
246
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// MARK: - getUrl
|
|
250
|
+
|
|
251
|
+
@objc public func getUrl(_ dbName: String) throws -> String {
|
|
252
|
+
if isInit {
|
|
253
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
254
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
255
|
+
let msg = "Connection to \(mDbName) not available"
|
|
256
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
257
|
+
}
|
|
258
|
+
let res: String = mDb.getUrl()
|
|
259
|
+
return res
|
|
260
|
+
} else {
|
|
261
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
178
262
|
}
|
|
179
263
|
}
|
|
180
264
|
|
|
181
265
|
// MARK: - GetVersion
|
|
182
266
|
|
|
183
267
|
@objc public func getVersion(_ dbName: String) throws -> NSNumber {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
let
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
268
|
+
if isInit {
|
|
269
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
270
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
271
|
+
let msg = "Connection to \(mDbName) not available"
|
|
272
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
273
|
+
}
|
|
274
|
+
do {
|
|
275
|
+
let version: Int = try mDb.getVersion()
|
|
276
|
+
return NSNumber(value: version)
|
|
192
277
|
|
|
193
|
-
|
|
194
|
-
|
|
278
|
+
} catch DatabaseError.open(let message) {
|
|
279
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
195
283
|
}
|
|
196
284
|
}
|
|
197
285
|
|
|
198
286
|
// MARK: - Close Connection
|
|
199
287
|
|
|
200
288
|
@objc public func closeConnection(_ dbName: String) throws {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
let
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
289
|
+
if isInit {
|
|
290
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
291
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
292
|
+
let msg = "Connection to \(mDbName) not available"
|
|
293
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
294
|
+
}
|
|
295
|
+
if mDb.isDBOpen() {
|
|
296
|
+
do {
|
|
297
|
+
try mDb.close()
|
|
298
|
+
} catch DatabaseError.close(let message) {
|
|
299
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
300
|
+
}
|
|
211
301
|
}
|
|
302
|
+
dbDict.removeValue(forKey: mDbName)
|
|
303
|
+
return
|
|
304
|
+
} else {
|
|
305
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
212
306
|
}
|
|
213
|
-
dbDict.removeValue(forKey: mDbName)
|
|
214
|
-
return
|
|
215
307
|
}
|
|
216
308
|
|
|
217
309
|
// MARK: - CheckConnectionsConsistency
|
|
218
310
|
|
|
219
311
|
@objc public func checkConnectionsConsistency(_ dbNames: [String]) throws -> NSNumber {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
312
|
+
if isInit {
|
|
313
|
+
var keys: [String] = Array(self.dbDict.keys)
|
|
314
|
+
do {
|
|
315
|
+
if dbNames.count == 0 {
|
|
316
|
+
try closeAllConnections()
|
|
317
|
+
return 0
|
|
318
|
+
}
|
|
319
|
+
if keys.count < dbNames.count {
|
|
320
|
+
// not solvable inconsistency
|
|
321
|
+
try closeAllConnections()
|
|
322
|
+
return 0
|
|
323
|
+
}
|
|
324
|
+
if keys.count > dbNames.count {
|
|
325
|
+
for key in keys {
|
|
326
|
+
if !dbNames.contains(key) {
|
|
327
|
+
self.dbDict.removeValue(forKey: key)
|
|
328
|
+
}
|
|
235
329
|
}
|
|
236
330
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
331
|
+
keys = Array(self.dbDict.keys)
|
|
332
|
+
if keys.count == dbNames.count {
|
|
333
|
+
let set1 = Set(keys)
|
|
334
|
+
let set2 = Set(dbNames)
|
|
335
|
+
let arr = Array(set1.symmetricDifference(set2))
|
|
336
|
+
if arr.count == 0 {
|
|
337
|
+
return 1
|
|
338
|
+
} else {
|
|
339
|
+
// not solvable inconsistency
|
|
340
|
+
try closeAllConnections()
|
|
341
|
+
return 0
|
|
342
|
+
}
|
|
245
343
|
} else {
|
|
246
|
-
// not solvable inconsistency
|
|
247
344
|
try closeAllConnections()
|
|
248
345
|
return 0
|
|
249
346
|
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return 0
|
|
347
|
+
} catch let error {
|
|
348
|
+
throw CapacitorSQLiteError.failed(message: "\(error)")
|
|
253
349
|
}
|
|
254
|
-
}
|
|
255
|
-
throw CapacitorSQLiteError.failed(message:
|
|
350
|
+
} else {
|
|
351
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
256
352
|
}
|
|
257
353
|
}
|
|
258
354
|
|
|
259
355
|
// MARK: - IsDatabase
|
|
260
356
|
|
|
261
357
|
@objc public func isDatabase(_ dbName: String) throws -> NSNumber {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
358
|
+
if isInit {
|
|
359
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
360
|
+
let isFileExists: Bool = UtilsFile
|
|
361
|
+
.isFileExist(databaseLocation: databaseLocation,
|
|
362
|
+
fileName: mDbName + "SQLite.db")
|
|
363
|
+
if isFileExists {
|
|
364
|
+
return 1
|
|
365
|
+
} else {
|
|
366
|
+
return 0
|
|
367
|
+
}
|
|
267
368
|
} else {
|
|
268
|
-
|
|
369
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
269
370
|
}
|
|
270
371
|
}
|
|
271
372
|
|
|
272
373
|
// MARK: - IsNCDatabase
|
|
273
374
|
|
|
274
375
|
@objc public func isNCDatabase(_ databasePath: String) throws -> NSNumber {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
376
|
+
if isInit {
|
|
377
|
+
let isFileExists: Bool = UtilsFile
|
|
378
|
+
.isFileExist(filePath: databasePath)
|
|
379
|
+
if isFileExists {
|
|
380
|
+
return 1
|
|
381
|
+
} else {
|
|
382
|
+
return 0
|
|
383
|
+
}
|
|
279
384
|
} else {
|
|
280
|
-
|
|
385
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
281
386
|
}
|
|
282
387
|
}
|
|
283
388
|
|
|
284
389
|
// MARK: - IsTableExists
|
|
285
390
|
|
|
286
391
|
@objc public func isTableExists(_ dbName: String, tableName: String) throws -> NSNumber {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
let
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
do {
|
|
293
|
-
let isExists: Bool = try
|
|
294
|
-
UtilsJson.isTableExists(mDB: mDb,
|
|
295
|
-
tableName: tableName)
|
|
296
|
-
if isExists {
|
|
297
|
-
return 1
|
|
298
|
-
} else {
|
|
299
|
-
return 0
|
|
392
|
+
if isInit {
|
|
393
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
394
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
395
|
+
let msg = "Connection to \(mDbName) not available"
|
|
396
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
300
397
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
398
|
+
do {
|
|
399
|
+
let isExists: Bool = try
|
|
400
|
+
UtilsJson.isTableExists(mDB: mDb,
|
|
401
|
+
tableName: tableName)
|
|
402
|
+
if isExists {
|
|
403
|
+
return 1
|
|
404
|
+
} else {
|
|
405
|
+
return 0
|
|
406
|
+
}
|
|
407
|
+
} catch UtilsJsonError.tableNotExists(let message) {
|
|
408
|
+
var msg: String = "IsTableExists:"
|
|
409
|
+
msg.append(" \(message)")
|
|
410
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
411
|
+
} catch let error {
|
|
412
|
+
var msg: String = "IsTableExists:"
|
|
413
|
+
msg.append(" \(error)")
|
|
414
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
309
418
|
}
|
|
310
419
|
}
|
|
311
420
|
|
|
@@ -314,37 +423,41 @@ enum CapacitorSQLiteError: Error {
|
|
|
314
423
|
@objc public func execute(_ dbName: String, statements: String,
|
|
315
424
|
transaction: Bool)
|
|
316
425
|
throws -> [String: Any] {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
let
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
426
|
+
if isInit {
|
|
427
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
428
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
429
|
+
let msg = "Connection to \(mDbName) not available"
|
|
430
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
431
|
+
}
|
|
432
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
433
|
+
do {
|
|
434
|
+
var stmts = statements
|
|
435
|
+
// remove carriage returns
|
|
436
|
+
let isReturn = stmts.indicesOf(string: "\n")
|
|
437
|
+
if isReturn.count != 0 {
|
|
438
|
+
let cmds = stmts.split(separator: "\n")
|
|
439
|
+
var strcmds: [String] = []
|
|
440
|
+
for cmd in cmds {
|
|
441
|
+
strcmds.append(String(cmd
|
|
442
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)))
|
|
443
|
+
}
|
|
444
|
+
stmts = strcmds.joined(separator: "\n")
|
|
333
445
|
}
|
|
334
|
-
|
|
446
|
+
let res = try mDb.executeSQL(sql: stmts,
|
|
447
|
+
transaction: transaction)
|
|
448
|
+
return ["changes": res]
|
|
449
|
+
} catch DatabaseError.executeSQL(let message) {
|
|
450
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
451
|
+
} catch let error {
|
|
452
|
+
let msg: String = "\(error)"
|
|
453
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
335
454
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return ["changes": res]
|
|
339
|
-
} catch DatabaseError.executeSQL(let message) {
|
|
340
|
-
throw CapacitorSQLiteError.failed(message: message)
|
|
341
|
-
} catch let error {
|
|
342
|
-
let msg: String = "\(error)"
|
|
455
|
+
} else {
|
|
456
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
343
457
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
344
458
|
}
|
|
345
459
|
} else {
|
|
346
|
-
|
|
347
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
460
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
348
461
|
}
|
|
349
462
|
}
|
|
350
463
|
|
|
@@ -353,24 +466,28 @@ enum CapacitorSQLiteError: Error {
|
|
|
353
466
|
@objc func executeSet(_ dbName: String, set: [[String: Any]],
|
|
354
467
|
transaction: Bool)
|
|
355
468
|
throws -> [String: Any] {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
let
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
469
|
+
if isInit {
|
|
470
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
471
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
472
|
+
let msg = "Connection to \(mDbName) not available"
|
|
473
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
474
|
+
}
|
|
475
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
476
|
+
do {
|
|
477
|
+
let res = try mDb.execSet(set: set, transaction: transaction)
|
|
478
|
+
return res
|
|
479
|
+
} catch DatabaseError.execSet(let message) {
|
|
480
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
481
|
+
} catch let error {
|
|
482
|
+
let msg: String = "\(error)"
|
|
483
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
369
487
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
370
488
|
}
|
|
371
489
|
} else {
|
|
372
|
-
|
|
373
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
490
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
374
491
|
}
|
|
375
492
|
}
|
|
376
493
|
|
|
@@ -380,46 +497,50 @@ enum CapacitorSQLiteError: Error {
|
|
|
380
497
|
@objc func run(_ dbName: String, statement: String, values: [Any],
|
|
381
498
|
transaction: Bool)
|
|
382
499
|
throws -> [String: Any] {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
let
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
let
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
500
|
+
if isInit {
|
|
501
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
502
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
503
|
+
let msg = "Connection to \(mDbName) not available"
|
|
504
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
505
|
+
}
|
|
506
|
+
if !mDb.isNCDB() && mDb.isDBOpen() {
|
|
507
|
+
do {
|
|
508
|
+
var val: [Any] = []
|
|
509
|
+
if values.count > 0 {
|
|
510
|
+
for value in values {
|
|
511
|
+
if let obj = value as? String {
|
|
512
|
+
let str: String =
|
|
513
|
+
"\(String(describing: obj))"
|
|
514
|
+
val.append(str)
|
|
515
|
+
} else if let obj = value as? Int {
|
|
516
|
+
val.append(obj)
|
|
517
|
+
} else if let obj = value as? Float {
|
|
518
|
+
val.append(obj)
|
|
519
|
+
} else if let obj = value as? Double {
|
|
520
|
+
val.append(obj)
|
|
521
|
+
} else if value is NSNull {
|
|
522
|
+
val.append(value)
|
|
523
|
+
} else {
|
|
524
|
+
let msg: String = "Not a SQL type"
|
|
525
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
526
|
+
}
|
|
408
527
|
}
|
|
409
528
|
}
|
|
529
|
+
let res = try mDb.runSQL(sql: statement, values: val,
|
|
530
|
+
transaction: transaction)
|
|
531
|
+
return res
|
|
532
|
+
} catch DatabaseError.runSQL(let message) {
|
|
533
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
534
|
+
} catch let error {
|
|
535
|
+
let msg: String = "\(error)"
|
|
536
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
410
537
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
return res
|
|
414
|
-
} catch DatabaseError.runSQL(let message) {
|
|
415
|
-
throw CapacitorSQLiteError.failed(message: message)
|
|
416
|
-
} catch let error {
|
|
417
|
-
let msg: String = "\(error)"
|
|
538
|
+
} else {
|
|
539
|
+
let msg = "Database \(mDbName) not opened or in read-only"
|
|
418
540
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
419
541
|
}
|
|
420
542
|
} else {
|
|
421
|
-
|
|
422
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
543
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
423
544
|
}
|
|
424
545
|
}
|
|
425
546
|
// swiftlint:enable cyclomatic_complexity
|
|
@@ -428,108 +549,127 @@ enum CapacitorSQLiteError: Error {
|
|
|
428
549
|
|
|
429
550
|
@objc func query(_ dbName: String, statement: String,
|
|
430
551
|
values: [Any]) throws -> [[String: Any]] {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
let
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
552
|
+
if isInit {
|
|
553
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
554
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
555
|
+
let msg = "Connection to \(mDbName) not available"
|
|
556
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
557
|
+
}
|
|
558
|
+
if mDb.isDBOpen() {
|
|
559
|
+
do {
|
|
560
|
+
let res: [[String: Any]] = try mDb
|
|
561
|
+
.selectSQL(sql: statement, values: values)
|
|
562
|
+
return res
|
|
563
|
+
} catch DatabaseError.selectSQL(let message) {
|
|
564
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
565
|
+
} catch let error {
|
|
566
|
+
let msg: String = "\(error)"
|
|
567
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
568
|
+
}
|
|
569
|
+
} else {
|
|
570
|
+
let msg = "Database \(mDbName) not opened"
|
|
445
571
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
446
572
|
}
|
|
447
573
|
} else {
|
|
448
|
-
|
|
449
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
574
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
450
575
|
}
|
|
451
576
|
}
|
|
452
577
|
|
|
453
578
|
// MARK: - isDBExists
|
|
454
579
|
|
|
455
580
|
@objc func isDBExists(_ dbName: String) throws -> NSNumber {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
let
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
581
|
+
if isInit {
|
|
582
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
583
|
+
guard let _: Database = dbDict[mDbName] else {
|
|
584
|
+
let msg = "Connection to \(mDbName) not available"
|
|
585
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
586
|
+
}
|
|
587
|
+
let res: Bool = UtilsFile
|
|
588
|
+
.isFileExist(databaseLocation: databaseLocation,
|
|
589
|
+
fileName: "\(mDbName)SQLite.db")
|
|
590
|
+
if res {
|
|
591
|
+
return 1
|
|
592
|
+
} else {
|
|
593
|
+
return 0
|
|
594
|
+
}
|
|
465
595
|
} else {
|
|
466
|
-
|
|
596
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
467
597
|
}
|
|
468
598
|
}
|
|
469
599
|
|
|
470
600
|
// MARK: - isDBOpen
|
|
471
601
|
|
|
472
602
|
@objc func isDBOpen(_ dbName: String) throws -> NSNumber {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
let
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
603
|
+
if isInit {
|
|
604
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
605
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
606
|
+
let msg = "Connection to \(mDbName) not available"
|
|
607
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
608
|
+
}
|
|
609
|
+
let isOpen: Bool = mDb.isDBOpen()
|
|
610
|
+
if isOpen {
|
|
611
|
+
return 1
|
|
612
|
+
} else {
|
|
613
|
+
return 0
|
|
614
|
+
}
|
|
481
615
|
} else {
|
|
482
|
-
|
|
616
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
483
617
|
}
|
|
484
618
|
}
|
|
485
619
|
|
|
486
620
|
// MARK: - deleteDatabase
|
|
487
621
|
|
|
488
622
|
@objc func deleteDatabase(_ dbName: String) throws {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
let
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
do {
|
|
496
|
-
if !mDb.isDBOpen() {
|
|
497
|
-
try mDb.open()
|
|
623
|
+
if isInit {
|
|
624
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
625
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
626
|
+
let msg = "Connection to \(mDbName) not available"
|
|
627
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
498
628
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
let
|
|
629
|
+
|
|
630
|
+
do {
|
|
631
|
+
if !mDb.isDBOpen() {
|
|
632
|
+
try mDb.open()
|
|
633
|
+
}
|
|
634
|
+
let res: Bool = try mDb.deleteDB(databaseName: "\(mDbName)SQLite.db")
|
|
635
|
+
if res {
|
|
636
|
+
return
|
|
637
|
+
} else {
|
|
638
|
+
let msg: String = "deleteDB return false"
|
|
639
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
640
|
+
}
|
|
641
|
+
} catch DatabaseError.open(let message) {
|
|
642
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
643
|
+
} catch DatabaseError.deleteDB(let message) {
|
|
644
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
645
|
+
} catch let error {
|
|
646
|
+
let msg: String = "\(error)"
|
|
505
647
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
506
648
|
}
|
|
507
|
-
}
|
|
508
|
-
throw CapacitorSQLiteError.failed(message:
|
|
509
|
-
} catch DatabaseError.deleteDB(let message) {
|
|
510
|
-
throw CapacitorSQLiteError.failed(message: message)
|
|
511
|
-
} catch let error {
|
|
512
|
-
let msg: String = "\(error)"
|
|
513
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
649
|
+
} else {
|
|
650
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
514
651
|
}
|
|
515
652
|
}
|
|
516
653
|
|
|
517
654
|
// MARK: - isJsonValid
|
|
518
655
|
|
|
519
656
|
@objc func isJsonValid(_ parsingData: String) throws {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
657
|
+
if isInit {
|
|
658
|
+
if let data = ("["+parsingData+"]").data(using: .utf8) {
|
|
659
|
+
do {
|
|
660
|
+
_ = try JSONDecoder().decode([JsonSQLite].self,
|
|
661
|
+
from: data)
|
|
662
|
+
return
|
|
663
|
+
} catch let error {
|
|
664
|
+
let msg: String = "\(error)"
|
|
665
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
666
|
+
}
|
|
667
|
+
} else {
|
|
668
|
+
let msg: String = "Stringify Json Object not Valid"
|
|
528
669
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
529
670
|
}
|
|
530
671
|
} else {
|
|
531
|
-
|
|
532
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
672
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
533
673
|
}
|
|
534
674
|
}
|
|
535
675
|
|
|
@@ -538,67 +678,72 @@ enum CapacitorSQLiteError: Error {
|
|
|
538
678
|
// swiftlint:disable function_body_length
|
|
539
679
|
@objc func importFromJson(_ parsingData: String)
|
|
540
680
|
throws -> [String: Int] {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
let encrypted: Bool = jsonSQLite[0].encrypted
|
|
553
|
-
let inMode: String = encrypted ? "secret"
|
|
554
|
-
: "no-encryption"
|
|
555
|
-
let version: Int = jsonSQLite[0].version
|
|
556
|
-
var dbName: String = CapacitorSQLite.getDatabaseName(dbName: jsonSQLite[0].database)
|
|
557
|
-
dbName.append("SQLite.db")
|
|
558
|
-
// open the database
|
|
559
|
-
do {
|
|
560
|
-
mDb = try Database(
|
|
561
|
-
databaseName: dbName, encrypted: encrypted,
|
|
562
|
-
mode: inMode, version: version, vUpgDict: [:])
|
|
563
|
-
try mDb.open()
|
|
564
|
-
} catch DatabaseError.open(let message) {
|
|
565
|
-
throw CapacitorSQLiteError.failed(message: message)
|
|
566
|
-
} catch let error {
|
|
567
|
-
let msg: String = "\(error)"
|
|
568
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
569
|
-
}
|
|
570
|
-
// import from Json Object
|
|
571
|
-
do {
|
|
572
|
-
let res: [String: Int] = try mDb
|
|
573
|
-
.importFromJson(jsonSQLite: jsonSQLite[0])
|
|
574
|
-
try mDb.close()
|
|
575
|
-
if let result = res["changes"] {
|
|
576
|
-
if result < 0 {
|
|
577
|
-
let msg: String = "changes < 0"
|
|
578
|
-
throw CapacitorSQLiteError
|
|
579
|
-
.failed(message: msg)
|
|
580
|
-
} else {
|
|
581
|
-
return res
|
|
582
|
-
}
|
|
583
|
-
} else {
|
|
584
|
-
let msg: String = "changes not found"
|
|
681
|
+
if isInit {
|
|
682
|
+
var mDb: Database
|
|
683
|
+
if let data = ("["+parsingData+"]").data(using: .utf8) {
|
|
684
|
+
var jsonSQLite: [JsonSQLite]
|
|
685
|
+
do {
|
|
686
|
+
jsonSQLite = try JSONDecoder()
|
|
687
|
+
.decode([JsonSQLite].self, from: data)
|
|
688
|
+
} catch let error {
|
|
689
|
+
var msg: String = "Stringify Json Object not Valid "
|
|
690
|
+
msg.append("\(error)")
|
|
585
691
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
586
692
|
}
|
|
587
|
-
|
|
588
|
-
|
|
693
|
+
let encrypted: Bool = jsonSQLite[0].encrypted
|
|
694
|
+
let inMode: String = encrypted ? "secret"
|
|
695
|
+
: "no-encryption"
|
|
696
|
+
let version: Int = jsonSQLite[0].version
|
|
697
|
+
var dbName: String = CapacitorSQLite.getDatabaseName(dbName: jsonSQLite[0].database)
|
|
698
|
+
dbName.append("SQLite.db")
|
|
699
|
+
// open the database
|
|
589
700
|
do {
|
|
590
|
-
try
|
|
701
|
+
mDb = try Database(
|
|
702
|
+
databaseLocation: databaseLocation,
|
|
703
|
+
databaseName: dbName, encrypted: encrypted,
|
|
704
|
+
mode: inMode, version: version, vUpgDict: [:])
|
|
705
|
+
try mDb.open()
|
|
706
|
+
} catch DatabaseError.open(let message) {
|
|
707
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
708
|
+
} catch let error {
|
|
709
|
+
let msg: String = "\(error)"
|
|
591
710
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
711
|
+
}
|
|
712
|
+
// import from Json Object
|
|
713
|
+
do {
|
|
714
|
+
let res: [String: Int] = try mDb
|
|
715
|
+
.importFromJson(jsonSQLite: jsonSQLite[0])
|
|
716
|
+
try mDb.close()
|
|
717
|
+
if let result = res["changes"] {
|
|
718
|
+
if result < 0 {
|
|
719
|
+
let msg: String = "changes < 0"
|
|
720
|
+
throw CapacitorSQLiteError
|
|
721
|
+
.failed(message: msg)
|
|
722
|
+
} else {
|
|
723
|
+
return res
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
let msg: String = "changes not found"
|
|
727
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
728
|
+
}
|
|
729
|
+
} catch DatabaseError.importFromJson(let message) {
|
|
730
|
+
var msg = message
|
|
731
|
+
do {
|
|
732
|
+
try mDb.close()
|
|
733
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
734
|
+
} catch DatabaseError.close(let message) {
|
|
735
|
+
msg.append(" \(message)")
|
|
736
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
737
|
+
}
|
|
592
738
|
} catch DatabaseError.close(let message) {
|
|
593
|
-
|
|
594
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
739
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
595
740
|
}
|
|
596
|
-
}
|
|
597
|
-
|
|
741
|
+
} else {
|
|
742
|
+
let msg: String = "Stringify Json Object not Valid"
|
|
743
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
598
744
|
}
|
|
599
745
|
} else {
|
|
600
|
-
|
|
601
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
746
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
602
747
|
}
|
|
603
748
|
}
|
|
604
749
|
// swiftlint:enable function_body_length
|
|
@@ -607,56 +752,64 @@ enum CapacitorSQLiteError: Error {
|
|
|
607
752
|
|
|
608
753
|
@objc func exportToJson(_ dbName: String, expMode: String)
|
|
609
754
|
throws -> [String: Any] {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
let
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
755
|
+
if isInit {
|
|
756
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
757
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
758
|
+
let msg = "Connection to \(mDbName) not available"
|
|
759
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
760
|
+
}
|
|
761
|
+
if mDb.isDBOpen() {
|
|
616
762
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
763
|
+
do {
|
|
764
|
+
let res: [String: Any] = try
|
|
765
|
+
mDb.exportToJson(expMode: expMode)
|
|
766
|
+
if res.count == 5 || res.count == 6 {
|
|
767
|
+
return res
|
|
768
|
+
} else {
|
|
769
|
+
var msg: String = "return Object is not a "
|
|
770
|
+
msg.append("JsonSQLite Object")
|
|
771
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
772
|
+
}
|
|
773
|
+
} catch DatabaseError.exportToJson(let message) {
|
|
774
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
775
|
+
} catch let error {
|
|
776
|
+
let msg: String = "\(error)"
|
|
625
777
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
626
778
|
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
} catch let error {
|
|
630
|
-
let msg: String = "\(error)"
|
|
779
|
+
} else {
|
|
780
|
+
let msg = "Database \(mDbName) not opened"
|
|
631
781
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
632
782
|
}
|
|
633
783
|
} else {
|
|
634
|
-
|
|
635
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
784
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
636
785
|
}
|
|
637
786
|
}
|
|
638
787
|
|
|
639
788
|
// MARK: - createSyncTable
|
|
640
789
|
|
|
641
790
|
@objc func createSyncTable(_ dbName: String) throws -> NSNumber {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
let
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
791
|
+
if isInit {
|
|
792
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
793
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
794
|
+
let msg = "Connection to \(mDbName) not available"
|
|
795
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
796
|
+
}
|
|
797
|
+
if mDb.isDBOpen() {
|
|
798
|
+
do {
|
|
799
|
+
let res: Int = try mDb.createSyncTable()
|
|
800
|
+
return res as NSNumber
|
|
801
|
+
} catch DatabaseError.createSyncTable(let message) {
|
|
802
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
803
|
+
} catch let error {
|
|
804
|
+
let msg: String = "\(error)"
|
|
805
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
806
|
+
}
|
|
807
|
+
} else {
|
|
808
|
+
let msg = "Database \(mDbName) not opened"
|
|
655
809
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
656
810
|
}
|
|
657
811
|
} else {
|
|
658
|
-
|
|
659
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
812
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
660
813
|
}
|
|
661
814
|
}
|
|
662
815
|
|
|
@@ -664,60 +817,68 @@ enum CapacitorSQLiteError: Error {
|
|
|
664
817
|
|
|
665
818
|
@objc func setSyncDate(_ dbName: String, syncDate: String)
|
|
666
819
|
throws {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
let
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
820
|
+
if isInit {
|
|
821
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
822
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
823
|
+
let msg = "Connection to \(mDbName) not available"
|
|
824
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
825
|
+
}
|
|
826
|
+
if mDb.isDBOpen() {
|
|
673
827
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
828
|
+
do {
|
|
829
|
+
let res: Bool = try mDb
|
|
830
|
+
.setSyncDate(syncDate: syncDate)
|
|
831
|
+
if res {
|
|
832
|
+
return
|
|
833
|
+
} else {
|
|
834
|
+
let msg: String = "return false"
|
|
835
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
836
|
+
}
|
|
837
|
+
} catch DatabaseError.createSyncDate(let message) {
|
|
838
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
839
|
+
} catch let error {
|
|
840
|
+
let msg: String = "\(error)"
|
|
681
841
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
682
842
|
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
} catch let error {
|
|
686
|
-
let msg: String = "\(error)"
|
|
843
|
+
} else {
|
|
844
|
+
let msg = "Database \(mDbName) not opened"
|
|
687
845
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
688
846
|
}
|
|
689
847
|
} else {
|
|
690
|
-
|
|
691
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
848
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
692
849
|
}
|
|
693
850
|
}
|
|
694
851
|
|
|
695
852
|
// MARK: - getSyncDate
|
|
696
853
|
|
|
697
854
|
@objc func getSyncDate(_ dbName: String) throws -> NSNumber {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
let
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
855
|
+
if isInit {
|
|
856
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
857
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
858
|
+
let msg = "Connection to \(mDbName) not available"
|
|
859
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
860
|
+
}
|
|
861
|
+
if mDb.isDBOpen() {
|
|
862
|
+
do {
|
|
863
|
+
let res: Int64 = try mDb.getSyncDate()
|
|
864
|
+
if res > 0 {
|
|
865
|
+
return res as NSNumber
|
|
866
|
+
} else {
|
|
867
|
+
let msg: String = "return no sync date"
|
|
868
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
869
|
+
}
|
|
870
|
+
} catch DatabaseError.getSyncDate(let message) {
|
|
871
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
872
|
+
} catch let error {
|
|
873
|
+
let msg: String = "\(error)"
|
|
710
874
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
711
875
|
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
} catch let error {
|
|
715
|
-
let msg: String = "\(error)"
|
|
876
|
+
} else {
|
|
877
|
+
let msg = "Database \(mDbName) not opened"
|
|
716
878
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
717
879
|
}
|
|
718
880
|
} else {
|
|
719
|
-
|
|
720
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
881
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
721
882
|
}
|
|
722
883
|
}
|
|
723
884
|
|
|
@@ -726,151 +887,176 @@ enum CapacitorSQLiteError: Error {
|
|
|
726
887
|
@objc func addUpgradeStatement(_ dbName: String,
|
|
727
888
|
upgrade: [[String: Any]])
|
|
728
889
|
throws -> [Int: [String: Any]] {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
!(keys.contains("
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
890
|
+
if isInit {
|
|
891
|
+
var upgDict: [String: Any] = [:]
|
|
892
|
+
for dict in upgrade {
|
|
893
|
+
let keys = dict.keys
|
|
894
|
+
if !(keys.contains("fromVersion")) ||
|
|
895
|
+
!(keys.contains("toVersion")) ||
|
|
896
|
+
!(keys.contains("statement")) {
|
|
897
|
+
var msg: String = "upgrade must have keys in "
|
|
898
|
+
msg.append("{fromVersion,toVersion,statement}")
|
|
899
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
900
|
+
}
|
|
901
|
+
for (key, value) in dict {
|
|
902
|
+
upgDict[key] = value
|
|
903
|
+
}
|
|
738
904
|
}
|
|
739
|
-
|
|
740
|
-
|
|
905
|
+
guard let fromVersion = upgDict["fromVersion"] as? Int else {
|
|
906
|
+
let msg: String = "fromVersion key must be an Int"
|
|
907
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
741
908
|
}
|
|
909
|
+
let upgVersionDict: [Int: [String: Any]] =
|
|
910
|
+
[fromVersion: upgDict]
|
|
911
|
+
return upgVersionDict
|
|
912
|
+
} else {
|
|
913
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
742
914
|
}
|
|
743
|
-
guard let fromVersion = upgDict["fromVersion"] as? Int else {
|
|
744
|
-
let msg: String = "fromVersion key must be an Int"
|
|
745
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
746
|
-
}
|
|
747
|
-
let upgVersionDict: [Int: [String: Any]] =
|
|
748
|
-
[fromVersion: upgDict]
|
|
749
|
-
return upgVersionDict
|
|
750
915
|
}
|
|
751
916
|
|
|
752
917
|
// MARK: - copyFromAssets
|
|
753
918
|
|
|
754
919
|
@objc func copyFromAssets(overwrite: Bool) throws {
|
|
920
|
+
if isInit {
|
|
755
921
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
922
|
+
// check if the assets/database folder exists
|
|
923
|
+
do {
|
|
924
|
+
let assetsDbPath: URL = try
|
|
925
|
+
UtilsFile.getAssetsDatabasesPath()
|
|
926
|
+
let aPath: String = assetsDbPath.path
|
|
927
|
+
let bRes: Bool = UtilsFile.isDirExist(dirPath: aPath)
|
|
928
|
+
if bRes {
|
|
929
|
+
// get the database files from assets
|
|
930
|
+
let dbList: [String] = try UtilsFile
|
|
931
|
+
.getFileList(path: aPath, ext: ".db")
|
|
932
|
+
// loop through the database files
|
|
933
|
+
for mDb in dbList {
|
|
934
|
+
// for each check if the suffix SQLite.db is there
|
|
935
|
+
// or add it
|
|
936
|
+
let toDb: String = UtilsFile
|
|
937
|
+
.setPathSuffix(sDb: mDb)
|
|
938
|
+
// for each copy the file to the Application
|
|
939
|
+
// database folder
|
|
940
|
+
_ = try UtilsFile
|
|
941
|
+
.copyFromAssetToDatabase(databaseLocation: databaseLocation,
|
|
942
|
+
fromDb: mDb,
|
|
943
|
+
toDb: toDb, overwrite: overwrite)
|
|
944
|
+
}
|
|
945
|
+
// get the zip files
|
|
946
|
+
let zipList: [String] = try UtilsFile
|
|
947
|
+
.getFileList(path: aPath, ext: ".zip")
|
|
948
|
+
// loop through the database files
|
|
949
|
+
for zip in zipList {
|
|
950
|
+
// for each zip uncompress the file to the Application
|
|
951
|
+
// database folder
|
|
952
|
+
_ = try UtilsFile
|
|
953
|
+
.unzipFromAssetToDatabase(databaseLocation: databaseLocation,
|
|
954
|
+
zip: zip, overwrite: overwrite)
|
|
955
|
+
}
|
|
956
|
+
return
|
|
957
|
+
} else {
|
|
958
|
+
let msg: String = "assets database path does not exist"
|
|
959
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
787
960
|
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
961
|
+
} catch UtilsFileError.copyFromAssetToDatabaseFailed(let message) {
|
|
962
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
963
|
+
} catch UtilsFileError.unzipFromAssetToDatabaseFailed(let message) {
|
|
964
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
965
|
+
} catch let error {
|
|
966
|
+
let msg: String = "\(error)"
|
|
791
967
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
792
968
|
}
|
|
793
|
-
}
|
|
794
|
-
throw CapacitorSQLiteError.failed(message:
|
|
795
|
-
} catch UtilsFileError.unzipFromAssetToDatabaseFailed(let message) {
|
|
796
|
-
throw CapacitorSQLiteError.failed(message: message)
|
|
797
|
-
} catch let error {
|
|
798
|
-
let msg: String = "\(error)"
|
|
799
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
969
|
+
} else {
|
|
970
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
800
971
|
}
|
|
801
972
|
}
|
|
802
973
|
|
|
803
974
|
// MARK: - getDatabaseList
|
|
804
975
|
|
|
805
976
|
@objc func getDatabaseList() throws -> [String] {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
977
|
+
if isInit {
|
|
978
|
+
do {
|
|
979
|
+
let aPath: String = try (UtilsFile.getFolderURL(folderPath: databaseLocation)).path
|
|
980
|
+
// get the database files
|
|
981
|
+
let dbList: [String] = try UtilsFile.getFileList(path: aPath, ext: ".db")
|
|
982
|
+
return dbList
|
|
811
983
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
984
|
+
} catch let error {
|
|
985
|
+
let msg: String = "\(error)"
|
|
986
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
987
|
+
}
|
|
988
|
+
} else {
|
|
989
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
815
990
|
}
|
|
816
|
-
|
|
817
991
|
}
|
|
818
992
|
|
|
819
993
|
// MARK: - getMigratableDbList
|
|
820
994
|
|
|
821
995
|
@objc func getMigratableDbList(_ folderPath: String) throws -> [String] {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
996
|
+
if isInit {
|
|
997
|
+
do {
|
|
998
|
+
let dbList: [String] = try UtilsMigrate
|
|
999
|
+
.getMigratableList(folderPath: folderPath)
|
|
1000
|
+
return dbList
|
|
826
1001
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1002
|
+
} catch UtilsMigrateError.getMigratableList(let message) {
|
|
1003
|
+
var msg: String = "getMigratableList:"
|
|
1004
|
+
msg.append(" \(message)")
|
|
1005
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1006
|
+
} catch let error {
|
|
1007
|
+
let msg: String = "\(error)"
|
|
1008
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1009
|
+
}
|
|
1010
|
+
} else {
|
|
1011
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
834
1012
|
}
|
|
835
|
-
|
|
836
1013
|
}
|
|
837
1014
|
|
|
838
1015
|
// MARK: - addSQLiteSuffix
|
|
839
1016
|
|
|
840
1017
|
@objc func addSQLiteSuffix(_ folderPath: String, dbList: [String]) throws {
|
|
1018
|
+
if isInit {
|
|
1019
|
+
do {
|
|
1020
|
+
try UtilsMigrate.addSQLiteSuffix(databaseLocation: databaseLocation,
|
|
1021
|
+
folderPath: folderPath,
|
|
1022
|
+
dbList: dbList)
|
|
1023
|
+
return
|
|
1024
|
+
} catch UtilsMigrateError.addSQLiteSuffix(let message) {
|
|
1025
|
+
var msg: String = "addSQLiteSuffix:"
|
|
1026
|
+
msg.append(" \(message)")
|
|
1027
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
841
1028
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
throw CapacitorSQLiteError.failed(message:
|
|
849
|
-
|
|
850
|
-
} catch let error {
|
|
851
|
-
var msg: String = "addSQLiteSuffix:"
|
|
852
|
-
msg.append(" \(error)")
|
|
853
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
1029
|
+
} catch let error {
|
|
1030
|
+
var msg: String = "addSQLiteSuffix:"
|
|
1031
|
+
msg.append(" \(error)")
|
|
1032
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1033
|
+
}
|
|
1034
|
+
} else {
|
|
1035
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
854
1036
|
}
|
|
855
1037
|
}
|
|
856
1038
|
|
|
857
1039
|
// MARK: - deleteOldDatabases
|
|
858
1040
|
|
|
859
1041
|
@objc func deleteOldDatabases(_ folderPath: String, dbList: [String]) throws {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
1042
|
+
if isInit {
|
|
1043
|
+
do {
|
|
1044
|
+
try UtilsMigrate
|
|
1045
|
+
.deleteOldDatabases(folderPath: folderPath, dbList: dbList)
|
|
1046
|
+
return
|
|
1047
|
+
} catch UtilsMigrateError.deleteOldDatabases(let message) {
|
|
1048
|
+
var msg: String = "deleteOldDatabases:"
|
|
1049
|
+
msg.append(" \(message)")
|
|
1050
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
867
1051
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
1052
|
+
} catch let error {
|
|
1053
|
+
var msg: String = "deleteOldDatabases:"
|
|
1054
|
+
msg.append(" \(error)")
|
|
1055
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1056
|
+
}
|
|
1057
|
+
} else {
|
|
1058
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
872
1059
|
}
|
|
873
|
-
|
|
874
1060
|
}
|
|
875
1061
|
class func getDatabaseName(dbName: String) -> String {
|
|
876
1062
|
var retName: String = dbName
|