@capacitor-community/sqlite 3.3.3-4 → 3.4.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -14
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +1 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +7 -4
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLite.java +19 -0
- package/ios/Plugin/CapacitorSQLite.swift +720 -576
- package/ios/Plugin/Database.swift +14 -3
- package/ios/Plugin/Utils/UtilsFile.swift +23 -24
- package/package.json +6 -6
- package/CHANGELOG.md +0 -1240
|
@@ -84,7 +84,7 @@ class Database {
|
|
|
84
84
|
// MARK: - getUrl
|
|
85
85
|
|
|
86
86
|
func getUrl () -> String {
|
|
87
|
-
return path
|
|
87
|
+
return "file://\(path)"
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// MARK: - Open
|
|
@@ -264,6 +264,16 @@ class Database {
|
|
|
264
264
|
throw DatabaseError.executeSQL(
|
|
265
265
|
message: "Failed in executeSQL : \(msg)" )
|
|
266
266
|
}
|
|
267
|
+
} else {
|
|
268
|
+
if transaction {
|
|
269
|
+
do {
|
|
270
|
+
try UtilsSQLCipher
|
|
271
|
+
.rollbackTransaction(mDB: self)
|
|
272
|
+
} catch UtilsSQLCipherError
|
|
273
|
+
.rollbackTransaction(let message) {
|
|
274
|
+
msg.append(" rollback: \(message)")
|
|
275
|
+
}
|
|
276
|
+
}
|
|
267
277
|
}
|
|
268
278
|
return changes
|
|
269
279
|
}
|
|
@@ -310,7 +320,7 @@ class Database {
|
|
|
310
320
|
msg.append(" \(message)")
|
|
311
321
|
throw DatabaseError.execSet(message: msg )
|
|
312
322
|
}
|
|
313
|
-
if changes
|
|
323
|
+
if changes >= 0 && transaction {
|
|
314
324
|
// commit the transaction
|
|
315
325
|
do {
|
|
316
326
|
try UtilsSQLCipher.commitTransaction(mDB: self)
|
|
@@ -321,6 +331,7 @@ class Database {
|
|
|
321
331
|
}
|
|
322
332
|
return changesDict
|
|
323
333
|
}
|
|
334
|
+
// swiftlint:enable function_body_length
|
|
324
335
|
|
|
325
336
|
// MARK: - RunSQL
|
|
326
337
|
|
|
@@ -368,8 +379,8 @@ class Database {
|
|
|
368
379
|
throw DatabaseError.runSQL(message: msg )
|
|
369
380
|
}
|
|
370
381
|
}
|
|
371
|
-
changes = UtilsSQLCipher.dbChanges(mDB: mDb) - initChanges
|
|
372
382
|
}
|
|
383
|
+
changes = UtilsSQLCipher.dbChanges(mDB: mDb) - initChanges
|
|
373
384
|
let result: [String: Int64] = ["changes": Int64(changes),
|
|
374
385
|
"lastId": lastId]
|
|
375
386
|
return result
|
|
@@ -29,24 +29,17 @@ enum UtilsFileError: Error {
|
|
|
29
29
|
case getFolderURLFailed(message: String)
|
|
30
30
|
case createDirFailed(message: String)
|
|
31
31
|
case moveAllDBSQLiteFailed(message: String)
|
|
32
|
+
case createDatabaseLocationFailed(message: String)
|
|
32
33
|
}
|
|
33
34
|
// swiftlint:disable file_length
|
|
34
35
|
// swiftlint:disable type_body_length
|
|
35
36
|
class UtilsFile {
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class func isDirExist(dirPath: String) -> Bool {
|
|
40
|
-
var isDir: ObjCBool = true
|
|
41
|
-
let fileManager = FileManager.default
|
|
42
|
-
let exists = fileManager.fileExists(atPath: dirPath, isDirectory: &isDir)
|
|
43
|
-
return exists && isDir.boolValue
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
class func createDirCopyDB(url: URL) throws {
|
|
38
|
+
class func createDatabaseLocation(location: String) throws {
|
|
47
39
|
do {
|
|
48
|
-
var dirUrl =
|
|
49
|
-
|
|
40
|
+
var dirUrl: URL = try UtilsFile
|
|
41
|
+
.getFolderURL(folderPath: location)
|
|
42
|
+
let dirPath: String = dirUrl.path
|
|
50
43
|
if !UtilsFile.isDirExist(dirPath: dirPath) {
|
|
51
44
|
// create the directory
|
|
52
45
|
try FileManager.default
|
|
@@ -54,20 +47,31 @@ class UtilsFile {
|
|
|
54
47
|
// exclude the directory from iCloud Backup
|
|
55
48
|
try UtilsFile.setExcludeFromiCloudBackup(&dirUrl,
|
|
56
49
|
isExcluded: true)
|
|
57
|
-
// move all
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
// move all existing dbs from "Documents" to location folder
|
|
51
|
+
if location.prefix(9) != "Documents" &&
|
|
52
|
+
location.prefix(7) != "default" {
|
|
53
|
+
|
|
54
|
+
try UtilsFile.moveAllDBSQLite(dirUrl: dirUrl)
|
|
55
|
+
}
|
|
60
56
|
}
|
|
61
57
|
} catch UtilsFileError.getFolderURLFailed(let message) {
|
|
62
|
-
throw UtilsFileError.
|
|
58
|
+
throw UtilsFileError.createDatabaseLocationFailed(message: message)
|
|
63
59
|
} catch UtilsFileError.moveAllDBSQLiteFailed(let message) {
|
|
64
|
-
throw UtilsFileError.
|
|
60
|
+
throw UtilsFileError.createDatabaseLocationFailed(message: message)
|
|
65
61
|
} catch let error {
|
|
66
|
-
var msg: String = "
|
|
62
|
+
var msg: String = "CreateDatabaseLocation command failed :"
|
|
67
63
|
msg.append(" \(error.localizedDescription)")
|
|
68
|
-
throw UtilsFileError.
|
|
64
|
+
throw UtilsFileError.createDatabaseLocationFailed(message: msg)
|
|
69
65
|
}
|
|
66
|
+
}
|
|
70
67
|
|
|
68
|
+
// MARK: - IsFileExist
|
|
69
|
+
|
|
70
|
+
class func isDirExist(dirPath: String) -> Bool {
|
|
71
|
+
var isDir: ObjCBool = true
|
|
72
|
+
let fileManager = FileManager.default
|
|
73
|
+
let exists = fileManager.fileExists(atPath: dirPath, isDirectory: &isDir)
|
|
74
|
+
return exists && isDir.boolValue
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
// MARK: - moveAllDBSQLite
|
|
@@ -175,11 +179,6 @@ class UtilsFile {
|
|
|
175
179
|
do {
|
|
176
180
|
let url: URL = try UtilsFile
|
|
177
181
|
.getFolderURL(folderPath: databaseLocation)
|
|
178
|
-
if databaseLocation.prefix(9) != "Documents" &&
|
|
179
|
-
databaseLocation.prefix(7) != "default" {
|
|
180
|
-
// create the directories if they do not exists
|
|
181
|
-
try UtilsFile.createDirCopyDB(url: url)
|
|
182
|
-
}
|
|
183
182
|
let dbPath: String = url
|
|
184
183
|
.appendingPathComponent("\(fileName)").path
|
|
185
184
|
return dbPath
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-1",
|
|
4
4
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@capacitor/android": "^3.
|
|
59
|
-
"@capacitor/core": "3.
|
|
60
|
-
"@capacitor/docgen": "^0.
|
|
61
|
-
"@capacitor/ios": "^3.
|
|
58
|
+
"@capacitor/android": "^3.4.0",
|
|
59
|
+
"@capacitor/core": "^3.4.0",
|
|
60
|
+
"@capacitor/docgen": "^0.1.1",
|
|
61
|
+
"@capacitor/ios": "^3.4.0",
|
|
62
62
|
"@ionic/eslint-config": "^0.3.0",
|
|
63
63
|
"@ionic/prettier-config": "^1.0.1",
|
|
64
64
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typescript": "~4.0.5"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@capacitor/core": "^3.
|
|
77
|
+
"@capacitor/core": "^3.4.0"
|
|
78
78
|
},
|
|
79
79
|
"prettier": "@ionic/prettier-config",
|
|
80
80
|
"swiftlint": "@ionic/swiftlint-config",
|