@capacitor-community/sqlite 3.4.2-1 → 3.4.2-4
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 +16 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +43 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +25 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +45 -22
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +13 -14
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +18 -9
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/JsonSQLite.java +26 -1
- package/dist/esm/definitions.d.ts +27 -3
- package/dist/esm/definitions.js +44 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +1 -0
- package/dist/esm/web.js +19 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +65 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1229 -1166
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +89 -35
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +73 -3
- package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +28 -1
- package/ios/Plugin/Database.swift +24 -14
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +6 -3
- package/ios/Plugin/ImportExportJson/JsonSQLite.swift +6 -0
- package/ios/Plugin/Utils/UtilsBinding.swift +2 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +11 -2
- package/package.json +2 -2
|
@@ -425,8 +425,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
425
425
|
if isInit {
|
|
426
426
|
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
427
427
|
guard let mDb: Database = dbDict[mDbName] else {
|
|
428
|
-
|
|
429
|
-
throw CapacitorSQLiteError.failed(message: msg)
|
|
428
|
+
return
|
|
430
429
|
}
|
|
431
430
|
if mDb.isDBOpen() {
|
|
432
431
|
do {
|
|
@@ -830,6 +829,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
830
829
|
// MARK: - importFromJson
|
|
831
830
|
|
|
832
831
|
// swiftlint:disable function_body_length
|
|
832
|
+
// swiftlint:disable cyclomatic_complexity
|
|
833
833
|
@objc func importFromJson(_ parsingData: String)
|
|
834
834
|
throws -> [String: Int] {
|
|
835
835
|
if isInit {
|
|
@@ -845,6 +845,11 @@ enum CapacitorSQLiteError: Error {
|
|
|
845
845
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
846
846
|
}
|
|
847
847
|
let encrypted: Bool = jsonSQLite[0].encrypted
|
|
848
|
+
var overwrite: Bool = false
|
|
849
|
+
if let mOverwrite = jsonSQLite[0].overwrite {
|
|
850
|
+
overwrite = mOverwrite
|
|
851
|
+
}
|
|
852
|
+
let mode: String = jsonSQLite[0].mode
|
|
848
853
|
let inMode: String = encrypted ? "secret"
|
|
849
854
|
: "no-encryption"
|
|
850
855
|
let version: Int = jsonSQLite[0].version
|
|
@@ -856,13 +861,49 @@ enum CapacitorSQLiteError: Error {
|
|
|
856
861
|
databaseLocation: databaseLocation, databaseName: dbName,
|
|
857
862
|
encrypted: encrypted, isEncryption: isEncryption, account: account,
|
|
858
863
|
mode: inMode, version: version, vUpgDict: [:])
|
|
864
|
+
if overwrite && mode == "full" {
|
|
865
|
+
let isExists = UtilsFile
|
|
866
|
+
.isFileExist(databaseLocation: databaseLocation,
|
|
867
|
+
fileName: dbName)
|
|
868
|
+
if isExists {
|
|
869
|
+
_ = try UtilsFile
|
|
870
|
+
.deleteFile(fileName: dbName,
|
|
871
|
+
databaseLocation: databaseLocation)
|
|
872
|
+
}
|
|
873
|
+
}
|
|
859
874
|
try mDb.open()
|
|
875
|
+
} catch UtilsFileError.deleteFileFailed {
|
|
876
|
+
let message = "Delete Database failed"
|
|
877
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
860
878
|
} catch DatabaseError.open(let message) {
|
|
861
879
|
throw CapacitorSQLiteError.failed(message: message)
|
|
862
880
|
} catch let error {
|
|
863
881
|
let msg: String = "\(error)"
|
|
864
882
|
throw CapacitorSQLiteError.failed(message: msg)
|
|
865
883
|
}
|
|
884
|
+
// check if the database as some tables
|
|
885
|
+
do {
|
|
886
|
+
let tableList: [String] = try mDb.getTableNames()
|
|
887
|
+
if mode == "full" && tableList.count > 0 {
|
|
888
|
+
let curVersion = try mDb.getVersion()
|
|
889
|
+
if version < curVersion {
|
|
890
|
+
var msg: String = "ImportFromJson: Cannot import a "
|
|
891
|
+
msg += "version lower than \(curVersion)"
|
|
892
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
893
|
+
}
|
|
894
|
+
if curVersion == version {
|
|
895
|
+
var res: [String: Int] = [:]
|
|
896
|
+
res["changes"] = 0
|
|
897
|
+
return res
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
} catch DatabaseError.getTableNames(let message) {
|
|
902
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
903
|
+
} catch let error {
|
|
904
|
+
let msg: String = "\(error)"
|
|
905
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
906
|
+
}
|
|
866
907
|
// import from Json Object
|
|
867
908
|
do {
|
|
868
909
|
let res: [String: Int] = try mDb
|
|
@@ -900,6 +941,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
900
941
|
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
901
942
|
}
|
|
902
943
|
}
|
|
944
|
+
// swiftlint:enable cyclomatic_complexity
|
|
903
945
|
// swiftlint:enable function_body_length
|
|
904
946
|
|
|
905
947
|
// MARK: - exportToJson
|
|
@@ -917,7 +959,7 @@ enum CapacitorSQLiteError: Error {
|
|
|
917
959
|
do {
|
|
918
960
|
let res: [String: Any] = try
|
|
919
961
|
mDb.exportToJson(expMode: expMode)
|
|
920
|
-
if res.count == 5 || res.count == 6 {
|
|
962
|
+
if res.count == 5 || res.count == 6 || res.count == 7 {
|
|
921
963
|
return res
|
|
922
964
|
} else {
|
|
923
965
|
var msg: String = "return Object is not a "
|
|
@@ -1125,6 +1167,34 @@ enum CapacitorSQLiteError: Error {
|
|
|
1125
1167
|
}
|
|
1126
1168
|
}
|
|
1127
1169
|
|
|
1170
|
+
// MARK: - getTableList
|
|
1171
|
+
|
|
1172
|
+
@objc func getTableList(_ dbName: String) throws -> [String] {
|
|
1173
|
+
if isInit {
|
|
1174
|
+
let mDbName = CapacitorSQLite.getDatabaseName(dbName: dbName)
|
|
1175
|
+
guard let mDb: Database = dbDict[mDbName] else {
|
|
1176
|
+
let msg = "Connection to \(mDbName) not available"
|
|
1177
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1178
|
+
}
|
|
1179
|
+
if mDb.isDBOpen() {
|
|
1180
|
+
do {
|
|
1181
|
+
let res: [String] = try mDb.getTableNames()
|
|
1182
|
+
return res
|
|
1183
|
+
} catch DatabaseError.getTableNames(let message) {
|
|
1184
|
+
throw CapacitorSQLiteError.failed(message: message)
|
|
1185
|
+
} catch let error {
|
|
1186
|
+
let msg: String = "\(error)"
|
|
1187
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1188
|
+
}
|
|
1189
|
+
} else {
|
|
1190
|
+
let msg = "Database \(mDbName) not opened"
|
|
1191
|
+
throw CapacitorSQLiteError.failed(message: msg)
|
|
1192
|
+
}
|
|
1193
|
+
} else {
|
|
1194
|
+
throw CapacitorSQLiteError.failed(message: initMessage)
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1128
1198
|
// MARK: - getDatabaseList
|
|
1129
1199
|
|
|
1130
1200
|
@objc func getDatabaseList() throws -> [String] {
|
|
@@ -33,6 +33,7 @@ CAP_PLUGIN(CapacitorSQLitePlugin, "CapacitorSQLite",
|
|
|
33
33
|
CAP_PLUGIN_METHOD(isNCDatabase, CAPPluginReturnPromise);
|
|
34
34
|
CAP_PLUGIN_METHOD(isTableExists, CAPPluginReturnPromise);
|
|
35
35
|
CAP_PLUGIN_METHOD(getDatabaseList, CAPPluginReturnPromise);
|
|
36
|
+
CAP_PLUGIN_METHOD(getTableList, CAPPluginReturnPromise);
|
|
36
37
|
CAP_PLUGIN_METHOD(getMigratableDbList, CAPPluginReturnPromise);
|
|
37
38
|
CAP_PLUGIN_METHOD(addSQLiteSuffix, CAPPluginReturnPromise);
|
|
38
39
|
CAP_PLUGIN_METHOD(deleteOldDatabases, CAPPluginReturnPromise);
|
|
@@ -395,6 +395,33 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
// MARK: - GetTableList
|
|
399
|
+
|
|
400
|
+
@objc func getTableList(_ call: CAPPluginCall) {
|
|
401
|
+
guard let dbName = call.options["database"] as? String else {
|
|
402
|
+
retHandler.rValues(
|
|
403
|
+
call: call, ret: [],
|
|
404
|
+
message: "getDatabaseList: Must provide a database name")
|
|
405
|
+
return
|
|
406
|
+
|
|
407
|
+
}
|
|
408
|
+
do {
|
|
409
|
+
let res = try implementation?.getTableList(dbName) ?? []
|
|
410
|
+
retHandler.rValues(call: call, ret: res)
|
|
411
|
+
return
|
|
412
|
+
} catch CapacitorSQLiteError.failed(let message) {
|
|
413
|
+
retHandler.rValues(
|
|
414
|
+
call: call, ret: [],
|
|
415
|
+
message: "getDatabaseList: \(message)")
|
|
416
|
+
return
|
|
417
|
+
} catch let error {
|
|
418
|
+
retHandler.rValues(
|
|
419
|
+
call: call, ret: [],
|
|
420
|
+
message: "getDatabaseList: \(error)")
|
|
421
|
+
return
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
398
425
|
// MARK: - getDatabaseList
|
|
399
426
|
|
|
400
427
|
@objc func getDatabaseList(_ call: CAPPluginCall) {
|
|
@@ -697,7 +724,7 @@ public class CapacitorSQLitePlugin: CAPPlugin {
|
|
|
697
724
|
|
|
698
725
|
}
|
|
699
726
|
do {
|
|
700
|
-
if let res = try
|
|
727
|
+
if let res: [[String: Any]] = try
|
|
701
728
|
implementation?.query(dbName,
|
|
702
729
|
statement: statement,
|
|
703
730
|
values: values) {
|
|
@@ -23,6 +23,7 @@ enum DatabaseError: Error {
|
|
|
23
23
|
case getSyncDate(message: String)
|
|
24
24
|
case exportToJson(message: String)
|
|
25
25
|
case importFromJson(message: String)
|
|
26
|
+
case getTableNames(message: String)
|
|
26
27
|
}
|
|
27
28
|
// swiftlint:disable file_length
|
|
28
29
|
// swiftlint:disable type_body_length
|
|
@@ -138,20 +139,16 @@ class Database {
|
|
|
138
139
|
try UtilsSQLCipher.setVersion(mDB: self, version: 1)
|
|
139
140
|
curVersion = try UtilsSQLCipher.getVersion(mDB: self)
|
|
140
141
|
}
|
|
141
|
-
if dbVersion > curVersion {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
databaseName: dbName)
|
|
152
|
-
} else {
|
|
153
|
-
try UtilsSQLCipher.setVersion(mDB: self, version: dbVersion)
|
|
154
|
-
}
|
|
142
|
+
if dbVersion > curVersion && vUpgDict.count > 0 {
|
|
143
|
+
_ = try uUpg
|
|
144
|
+
.onUpgrade(mDB: self, upgDict: vUpgDict,
|
|
145
|
+
dbName: dbName,
|
|
146
|
+
currentVersion: curVersion,
|
|
147
|
+
targetVersion: dbVersion,
|
|
148
|
+
databaseLocation: databaseLocation)
|
|
149
|
+
try UtilsSQLCipher
|
|
150
|
+
.deleteBackupDB(databaseLocation: databaseLocation,
|
|
151
|
+
databaseName: dbName)
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
154
|
} catch UtilsSQLCipherError.openOrCreateDatabase(let message) {
|
|
@@ -411,6 +408,19 @@ class Database {
|
|
|
411
408
|
return result
|
|
412
409
|
}
|
|
413
410
|
|
|
411
|
+
// MARK: - GetTableNames
|
|
412
|
+
|
|
413
|
+
func getTableNames() throws -> [String] {
|
|
414
|
+
var result: [String] = []
|
|
415
|
+
do {
|
|
416
|
+
result = try UtilsDrop.getTablesNames(mDB: self)
|
|
417
|
+
} catch UtilsDropError.getTablesNamesFailed(let msg) {
|
|
418
|
+
throw DatabaseError.getTableNames(
|
|
419
|
+
message: "Failed in getTableNames : \(msg)" )
|
|
420
|
+
}
|
|
421
|
+
return result
|
|
422
|
+
}
|
|
423
|
+
|
|
414
424
|
// MARK: - DeleteDB
|
|
415
425
|
|
|
416
426
|
func deleteDB(databaseName: String) throws -> Bool {
|
|
@@ -45,13 +45,16 @@ class ImportFromJson {
|
|
|
45
45
|
// Set PRAGMAS
|
|
46
46
|
try UtilsSQLCipher.setVersion(mDB: mDB,
|
|
47
47
|
version: version)
|
|
48
|
-
try UtilsSQLCipher
|
|
49
|
-
.setForeignKeyConstraintsEnabled(mDB: mDB,
|
|
50
|
-
toggle: true)
|
|
51
48
|
if jsonSQLite.mode == "full" {
|
|
49
|
+
try UtilsSQLCipher
|
|
50
|
+
.setForeignKeyConstraintsEnabled(mDB: mDB,
|
|
51
|
+
toggle: false)
|
|
52
52
|
// Drop All Tables, Indexes and Triggers
|
|
53
53
|
try _ = UtilsDrop.dropAll(mDB: mDB)
|
|
54
54
|
}
|
|
55
|
+
try UtilsSQLCipher
|
|
56
|
+
.setForeignKeyConstraintsEnabled(mDB: mDB,
|
|
57
|
+
toggle: true)
|
|
55
58
|
// create database schema
|
|
56
59
|
changes = try ImportFromJson
|
|
57
60
|
.createSchema(mDB: mDB,
|
|
@@ -10,6 +10,7 @@ import Foundation
|
|
|
10
10
|
public struct JsonSQLite: Codable {
|
|
11
11
|
let database: String
|
|
12
12
|
let version: Int
|
|
13
|
+
var overwrite: Bool?
|
|
13
14
|
let encrypted: Bool
|
|
14
15
|
let mode: String
|
|
15
16
|
let tables: [JsonTable]
|
|
@@ -18,6 +19,11 @@ public struct JsonSQLite: Codable {
|
|
|
18
19
|
public func show() {
|
|
19
20
|
print("databaseName: \(database) ")
|
|
20
21
|
print("version: \(version) ")
|
|
22
|
+
var mOverwrite = false
|
|
23
|
+
if let mOver = overwrite {
|
|
24
|
+
mOverwrite = mOver
|
|
25
|
+
}
|
|
26
|
+
print("overwrite: \(mOverwrite) ")
|
|
21
27
|
print("encrypted: \(encrypted) ")
|
|
22
28
|
print("mode: \(mode) ")
|
|
23
29
|
print("Number of Tables: \(tables.count) ")
|
|
@@ -42,6 +42,8 @@ class UtilsBinding {
|
|
|
42
42
|
sqlite3_bind_null(handle, Int32(idx))
|
|
43
43
|
} else if let value = value as? Double {
|
|
44
44
|
sqlite3_bind_double(handle, Int32(idx), value)
|
|
45
|
+
} else if let value = value as? Float {
|
|
46
|
+
sqlite3_bind_double(handle, Int32(idx), Double(value))
|
|
45
47
|
} else if let value = value as? Int64 {
|
|
46
48
|
sqlite3_bind_int64(handle, Int32(idx), value)
|
|
47
49
|
} else if let value = value as? String {
|
|
@@ -270,7 +270,7 @@ class UtilsSQLCipher {
|
|
|
270
270
|
sql: sqltr,
|
|
271
271
|
values: [])
|
|
272
272
|
if resVersion.count > 0 {
|
|
273
|
-
guard let res: Int64 = resVersion[
|
|
273
|
+
guard let res: Int64 = resVersion[1]["user_version"]
|
|
274
274
|
as? Int64 else {
|
|
275
275
|
throw UtilsSQLCipherError.getVersion(
|
|
276
276
|
message: "Error get version failed")
|
|
@@ -508,7 +508,9 @@ class UtilsSQLCipher {
|
|
|
508
508
|
throws -> [[String: Any]] {
|
|
509
509
|
var result: [[String: Any]] = []
|
|
510
510
|
var columnCount: Int32 = 0
|
|
511
|
-
|
|
511
|
+
var columnNames: [String] = []
|
|
512
|
+
var columnData: [String: Any] = [:]
|
|
513
|
+
|
|
512
514
|
while sqlite3_step(handle) == SQLITE_ROW {
|
|
513
515
|
columnCount = sqlite3_column_count(handle)
|
|
514
516
|
var rowData: [String: Any] = [:]
|
|
@@ -521,6 +523,13 @@ class UtilsSQLCipher {
|
|
|
521
523
|
throw UtilsSQLCipherError
|
|
522
524
|
.fetchColumnInfo(message: message)
|
|
523
525
|
}
|
|
526
|
+
if columnNames.count <= columnCount {
|
|
527
|
+
columnNames.append(String(cString: name))
|
|
528
|
+
if columnNames.count == columnCount {
|
|
529
|
+
columnData["ios_columns"] = columnNames
|
|
530
|
+
result.append(columnData)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
524
533
|
switch sqlite3_column_type(handle, Int32(index)) {
|
|
525
534
|
case SQLITE_INTEGER:
|
|
526
535
|
let val: Int64 = sqlite3_column_int64(handle, index)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "3.4.2-
|
|
3
|
+
"version": "3.4.2-4",
|
|
4
4
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -93,6 +93,6 @@
|
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"jeep-sqlite": "^1.
|
|
96
|
+
"jeep-sqlite": "^1.4.0"
|
|
97
97
|
}
|
|
98
98
|
}
|