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