@capacitor-community/sqlite 3.4.2-3 → 3.4.2
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 +20 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +2 -83
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +91 -5
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +90 -0
- package/dist/esm/definitions.d.ts +12 -5
- package/dist/esm/definitions.js +33 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +35 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1229 -1196
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +91 -43
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLitePlugin.swift +1 -1
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +63 -19
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +21 -12
- package/ios/Plugin/Utils/UtilsBinding.swift +2 -2
- package/ios/Plugin/Utils/UtilsDrop.swift +8 -4
- package/ios/Plugin/Utils/UtilsJson.swift +90 -9
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +14 -23
- package/ios/Plugin/Utils/UtilsUpgrade.swift +2 -1
- package/package.json +3 -3
|
@@ -28,9 +28,16 @@ enum ExportToJsonError: Error {
|
|
|
28
28
|
case modEmbeddedParentheses(message: String)
|
|
29
29
|
case getViews(message: String)
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
var REALAFFINITY: [String] = ["REAL", "DOUBLE", "DOUBLE PRECISION", "FLOAT"]
|
|
32
|
+
var INTEGERAFFINITY: [String] = ["INTEGER", "INT", "TINYINT", "SMALLINT",
|
|
33
|
+
"MEDIUMINT", "BIGINT", "UNSIGNED BIG INT",
|
|
34
|
+
"INT2", "INT8"]
|
|
35
|
+
var TEXTAFFINITY: [String] = ["TEXT", "CHARACTER", "VARCHAR", "VARYING CHARACTER",
|
|
36
|
+
"NCHAR", "NATIVE CHARACTER", "NVARCHAR", "CLOB"]
|
|
37
|
+
var BLOBAFFINITY: [String] = ["BLOB"]
|
|
38
|
+
var NUMERICAFFINITY: [String] = ["NUMERIC", "DECIMAL", "BOOLEAN", "DATE",
|
|
39
|
+
"DATETIME"]
|
|
32
40
|
class ExportToJson {
|
|
33
|
-
|
|
34
41
|
// MARK: - JsonNotifications - NotifyExportProgressEvent
|
|
35
42
|
|
|
36
43
|
class func notifyExportProgressEvent(msg: String) {
|
|
@@ -72,9 +79,10 @@ class ExportToJson {
|
|
|
72
79
|
// get the view's name
|
|
73
80
|
var stmtV: String = "SELECT name,sql FROM sqlite_master WHERE "
|
|
74
81
|
stmtV.append("type = 'view' AND name NOT LIKE 'sqlite_%';")
|
|
75
|
-
|
|
82
|
+
var resViews = try UtilsSQLCipher.querySQL(
|
|
76
83
|
mDB: mDB, sql: stmtV, values: [])
|
|
77
|
-
if resViews.count >
|
|
84
|
+
if resViews.count > 1 {
|
|
85
|
+
resViews.removeFirst()
|
|
78
86
|
views = try ExportToJson
|
|
79
87
|
.getViews(mDB: mDB,
|
|
80
88
|
resViews: resViews)
|
|
@@ -85,9 +93,10 @@ class ExportToJson {
|
|
|
85
93
|
var query: String = "SELECT name,sql FROM sqlite_master WHERE "
|
|
86
94
|
query.append("type = 'table' AND name NOT LIKE 'sqlite_%' ")
|
|
87
95
|
query.append("AND name NOT LIKE 'sync_table';")
|
|
88
|
-
|
|
96
|
+
var resTables = try UtilsSQLCipher.querySQL(
|
|
89
97
|
mDB: mDB, sql: query, values: [])
|
|
90
|
-
if resTables.count >
|
|
98
|
+
if resTables.count > 1 {
|
|
99
|
+
resTables.removeFirst()
|
|
91
100
|
let isExists: Bool = try UtilsJson.isTableExists(
|
|
92
101
|
mDB: mDB, tableName: "sync_table")
|
|
93
102
|
if !isExists && expMode == "partial" {
|
|
@@ -528,9 +537,10 @@ class ExportToJson {
|
|
|
528
537
|
var ret: Int64 = -1
|
|
529
538
|
let query: String = "SELECT sync_date FROM sync_table;"
|
|
530
539
|
do {
|
|
531
|
-
|
|
540
|
+
var resSyncDate = try UtilsSQLCipher.querySQL(
|
|
532
541
|
mDB: mDB, sql: query, values: [])
|
|
533
|
-
if resSyncDate.count >
|
|
542
|
+
if resSyncDate.count > 1 {
|
|
543
|
+
resSyncDate.removeFirst()
|
|
534
544
|
guard let res: Int64 = resSyncDate[0]["sync_date"] as?
|
|
535
545
|
Int64 else {
|
|
536
546
|
throw ExportToJsonError.getSyncDate(
|
|
@@ -548,6 +558,7 @@ class ExportToJson {
|
|
|
548
558
|
// MARK: - ExportToJson - GetTablesModified
|
|
549
559
|
|
|
550
560
|
// swiftlint:disable function_body_length
|
|
561
|
+
// swiftlint:disable cyclomatic_complexity
|
|
551
562
|
class func getTablesModified(mDB: Database,
|
|
552
563
|
tables: [[String: Any]],
|
|
553
564
|
syncDate: Int64)
|
|
@@ -569,6 +580,9 @@ class ExportToJson {
|
|
|
569
580
|
do {
|
|
570
581
|
var resQuery = try UtilsSQLCipher.querySQL(
|
|
571
582
|
mDB: mDB, sql: query, values: [])
|
|
583
|
+
if resQuery.count > 1 {
|
|
584
|
+
resQuery.removeFirst()
|
|
585
|
+
}
|
|
572
586
|
if resQuery.count != 1 {
|
|
573
587
|
break
|
|
574
588
|
} else {
|
|
@@ -585,6 +599,9 @@ class ExportToJson {
|
|
|
585
599
|
query.append("\(syncDate);")
|
|
586
600
|
resQuery = try UtilsSQLCipher.querySQL(
|
|
587
601
|
mDB: mDB, sql: query, values: [])
|
|
602
|
+
if resQuery.count > 1 {
|
|
603
|
+
resQuery.removeFirst()
|
|
604
|
+
}
|
|
588
605
|
if resQuery.count != 1 {
|
|
589
606
|
break
|
|
590
607
|
} else {
|
|
@@ -618,6 +635,8 @@ class ExportToJson {
|
|
|
618
635
|
}
|
|
619
636
|
return retObj
|
|
620
637
|
}
|
|
638
|
+
// swiftlint:enable cyclomatic_complexity
|
|
639
|
+
// swiftlint:enable function_body_length
|
|
621
640
|
|
|
622
641
|
// MARK: - ExportToJson - ModEmbeddedParentheses
|
|
623
642
|
|
|
@@ -751,9 +770,10 @@ class ExportToJson {
|
|
|
751
770
|
query.append("type = 'index' AND tbl_name = '\(tableName)' ")
|
|
752
771
|
query.append("AND sql NOTNULL;")
|
|
753
772
|
do {
|
|
754
|
-
|
|
773
|
+
var resIndexes = try UtilsSQLCipher.querySQL(
|
|
755
774
|
mDB: mDB, sql: query, values: [])
|
|
756
|
-
if resIndexes.count >
|
|
775
|
+
if resIndexes.count > 1 {
|
|
776
|
+
resIndexes.removeFirst()
|
|
757
777
|
for ipos in 0..<resIndexes.count {
|
|
758
778
|
var row: [String: String] = [:]
|
|
759
779
|
let keys: [String] = Array(resIndexes[ipos].keys)
|
|
@@ -837,9 +857,10 @@ class ExportToJson {
|
|
|
837
857
|
query.append("type = 'trigger' AND tbl_name = '\(tableName)' ")
|
|
838
858
|
query.append("AND sql NOTNULL;")
|
|
839
859
|
do {
|
|
840
|
-
|
|
860
|
+
var resTriggers = try UtilsSQLCipher.querySQL(
|
|
841
861
|
mDB: mDB, sql: query, values: [])
|
|
842
|
-
if resTriggers.count >
|
|
862
|
+
if resTriggers.count > 1 {
|
|
863
|
+
resTriggers.removeFirst()
|
|
843
864
|
for ipos in 0..<resTriggers.count {
|
|
844
865
|
var row: [String: String] = [:]
|
|
845
866
|
let keys: [String] = Array(resTriggers[ipos].keys)
|
|
@@ -952,9 +973,10 @@ class ExportToJson {
|
|
|
952
973
|
|
|
953
974
|
var retValues: [[Any]] = []
|
|
954
975
|
do {
|
|
955
|
-
|
|
976
|
+
var resValues = try UtilsSQLCipher.querySQL(
|
|
956
977
|
mDB: mDB, sql: query, values: [])
|
|
957
|
-
if resValues.count >
|
|
978
|
+
if resValues.count > 1 {
|
|
979
|
+
resValues.removeFirst()
|
|
958
980
|
for ipos in 0..<resValues.count {
|
|
959
981
|
var row: [Any] = []
|
|
960
982
|
do {
|
|
@@ -981,14 +1003,19 @@ class ExportToJson {
|
|
|
981
1003
|
|
|
982
1004
|
// MARK: - ExportToJson - CreateRowValues
|
|
983
1005
|
|
|
1006
|
+
// swiftlint:disable function_body_length
|
|
1007
|
+
// swiftlint:disable cyclomatic_complexity
|
|
984
1008
|
class func createRowValues(values: [[String: Any]], pos: Int,
|
|
985
1009
|
names: [String],
|
|
986
1010
|
types: [String] ) throws -> [Any] {
|
|
987
1011
|
var row: [Any] = []
|
|
988
1012
|
for jpos in 0..<names.count {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1013
|
+
if values[pos][names[jpos]] is String && (TEXTAFFINITY
|
|
1014
|
+
.contains(types[jpos].components(separatedBy: "(")[0]
|
|
1015
|
+
.uppercased())
|
|
1016
|
+
|| BLOBAFFINITY.contains(types[jpos].uppercased())
|
|
1017
|
+
|| NUMERICAFFINITY.contains(types[jpos].uppercased())
|
|
1018
|
+
) {
|
|
992
1019
|
guard let val = values[pos][names[jpos]] as? String
|
|
993
1020
|
else {
|
|
994
1021
|
throw ExportToJsonError.createValues(
|
|
@@ -1002,14 +1029,29 @@ class ExportToJson {
|
|
|
1002
1029
|
message: "Error value must be NSNull")
|
|
1003
1030
|
}
|
|
1004
1031
|
row.append(val)
|
|
1005
|
-
} else if values[pos][names[jpos]] is Int64
|
|
1032
|
+
} else if values[pos][names[jpos]] is Int64 && (
|
|
1033
|
+
INTEGERAFFINITY.contains(types[jpos].uppercased()) ||
|
|
1034
|
+
NUMERICAFFINITY.contains(types[jpos].uppercased())) {
|
|
1006
1035
|
guard let val = values[pos][names[jpos]] as? Int64
|
|
1007
1036
|
else {
|
|
1008
1037
|
throw ExportToJsonError.createValues(
|
|
1009
1038
|
message: "Error value must be Int64")
|
|
1010
1039
|
}
|
|
1011
1040
|
row.append(val)
|
|
1012
|
-
} else if values[pos][names[jpos]] is
|
|
1041
|
+
} else if values[pos][names[jpos]] is Int64 && (
|
|
1042
|
+
REALAFFINITY.contains(types[jpos].uppercased()) ||
|
|
1043
|
+
NUMERICAFFINITY.contains(types[jpos]
|
|
1044
|
+
.components(separatedBy: "(")[0].uppercased())) {
|
|
1045
|
+
guard let val = values[pos][names[jpos]] as? Int64
|
|
1046
|
+
else {
|
|
1047
|
+
throw ExportToJsonError.createValues(
|
|
1048
|
+
message: "Error value must be double")
|
|
1049
|
+
}
|
|
1050
|
+
row.append(Double(val))
|
|
1051
|
+
} else if values[pos][names[jpos]] is Double && (
|
|
1052
|
+
REALAFFINITY.contains(types[jpos].uppercased()) ||
|
|
1053
|
+
NUMERICAFFINITY.contains(types[jpos]
|
|
1054
|
+
.components(separatedBy: "(")[0].uppercased())) {
|
|
1013
1055
|
guard let val = values[pos][names[jpos]] as? Double
|
|
1014
1056
|
else {
|
|
1015
1057
|
throw ExportToJsonError.createValues(
|
|
@@ -1025,6 +1067,8 @@ class ExportToJson {
|
|
|
1025
1067
|
}
|
|
1026
1068
|
return row
|
|
1027
1069
|
}
|
|
1070
|
+
// swiftlint:enable cyclomatic_complexity
|
|
1071
|
+
// swiftlint:enable function_body_length
|
|
1028
1072
|
|
|
1029
1073
|
}
|
|
1030
1074
|
// swiftlint:enable type_body_length
|
|
@@ -236,7 +236,7 @@ class ImportFromJson {
|
|
|
236
236
|
stmt.append(" AFTER UPDATE ON ")
|
|
237
237
|
stmt.append(tableName)
|
|
238
238
|
stmt.append(" FOR EACH ROW ")
|
|
239
|
-
stmt.append("WHEN NEW.last_modified
|
|
239
|
+
stmt.append("WHEN NEW.last_modified < OLD.last_modified ")
|
|
240
240
|
stmt.append("BEGIN UPDATE ")
|
|
241
241
|
stmt.append(tableName)
|
|
242
242
|
stmt.append(" SET last_modified = (strftime('%s','now')) ")
|
|
@@ -409,6 +409,8 @@ class ImportFromJson {
|
|
|
409
409
|
// Check row validity
|
|
410
410
|
let row: [UncertainValue<String, Int, Double>] =
|
|
411
411
|
mValues[jpos]
|
|
412
|
+
var isRun: Bool = true
|
|
413
|
+
|
|
412
414
|
/* Remove types checking for allowing RDBMS Types
|
|
413
415
|
do {
|
|
414
416
|
try UtilsJson.checkRowValidity(
|
|
@@ -429,19 +431,26 @@ class ImportFromJson {
|
|
|
429
431
|
jsonNamesTypes: jsonNamesTypes)
|
|
430
432
|
let rowValues = UtilsJson.getValuesFromRow(
|
|
431
433
|
rowValues: row)
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
isRun = try UtilsJson.checkUpdate(mDB: mDB, stmt: stmt,
|
|
435
|
+
values: rowValues,
|
|
436
|
+
tableName: tableName,
|
|
437
|
+
names: jsonNamesTypes.names,
|
|
438
|
+
types: jsonNamesTypes.types)
|
|
439
|
+
|
|
440
|
+
if isRun {
|
|
441
|
+
let lastId: Int64 = try UtilsSQLCipher.prepareSQL(
|
|
442
|
+
mDB: mDB, sql: stmt, values: rowValues)
|
|
443
|
+
if lastId < 0 {
|
|
444
|
+
throw ImportFromJsonError.createTableData(
|
|
445
|
+
message: "lastId < 0")
|
|
446
|
+
}
|
|
437
447
|
}
|
|
438
|
-
} catch
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
448
|
+
} catch UtilsJsonError.checkUpdate(let message) {
|
|
449
|
+
throw ImportFromJsonError.createTableData(message: message)
|
|
450
|
+
} catch ImportFromJsonError.createRowStatement(let message) {
|
|
451
|
+
throw ImportFromJsonError.createTableData(message: message)
|
|
442
452
|
} catch UtilsSQLCipherError.prepareSQL(let message) {
|
|
443
|
-
throw ImportFromJsonError.createTableData(
|
|
444
|
-
message: message)
|
|
453
|
+
throw ImportFromJsonError.createTableData(message: message)
|
|
445
454
|
}
|
|
446
455
|
}
|
|
447
456
|
return
|
|
@@ -24,10 +24,10 @@ class UtilsBinding {
|
|
|
24
24
|
value: value, idx: idx)
|
|
25
25
|
idx += 1
|
|
26
26
|
} else {
|
|
27
|
-
message = "Error:
|
|
27
|
+
message = "Error: bindValues bind failed "
|
|
28
28
|
}
|
|
29
29
|
} catch let error as NSError {
|
|
30
|
-
message = "Error:
|
|
30
|
+
message = "Error: bindValues bind failed "
|
|
31
31
|
message.append("\(error.localizedDescription)")
|
|
32
32
|
}
|
|
33
33
|
if message.count > 0 { break }
|
|
@@ -33,8 +33,9 @@ class UtilsDrop {
|
|
|
33
33
|
query.append("AND name NOT LIKE 'sqlite_%' ")
|
|
34
34
|
query.append("ORDER BY rootpage DESC;")
|
|
35
35
|
do {
|
|
36
|
-
|
|
36
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
37
37
|
if resQuery.count > 0 {
|
|
38
|
+
resQuery.removeFirst()
|
|
38
39
|
for ipos in 0..<resQuery.count {
|
|
39
40
|
if let mName = resQuery[ipos]["name"] as? String {
|
|
40
41
|
names.append("\(mName)")
|
|
@@ -81,8 +82,9 @@ class UtilsDrop {
|
|
|
81
82
|
query.append("type='view' AND name NOT LIKE 'sqlite_%' ")
|
|
82
83
|
query.append("ORDER BY rootpage DESC;")
|
|
83
84
|
do {
|
|
84
|
-
|
|
85
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
85
86
|
if resQuery.count > 0 {
|
|
87
|
+
resQuery.removeFirst()
|
|
86
88
|
for ipos in 0..<resQuery.count {
|
|
87
89
|
if let mName = resQuery[ipos]["name"] as? String {
|
|
88
90
|
names.append("\(mName)")
|
|
@@ -128,8 +130,9 @@ class UtilsDrop {
|
|
|
128
130
|
var query: String = "SELECT name FROM sqlite_master WHERE "
|
|
129
131
|
query.append("type='index' AND name NOT LIKE 'sqlite_%';")
|
|
130
132
|
do {
|
|
131
|
-
|
|
133
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
132
134
|
if resQuery.count > 0 {
|
|
135
|
+
resQuery.removeFirst()
|
|
133
136
|
for ipos in 0..<resQuery.count {
|
|
134
137
|
if let mName = resQuery[ipos]["name"] as? String {
|
|
135
138
|
indexes.append("\(mName)")
|
|
@@ -174,8 +177,9 @@ class UtilsDrop {
|
|
|
174
177
|
var query: String = "SELECT name FROM sqlite_master WHERE "
|
|
175
178
|
query.append("type='trigger';")
|
|
176
179
|
do {
|
|
177
|
-
|
|
180
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
178
181
|
if resQuery.count > 0 {
|
|
182
|
+
resQuery.removeFirst()
|
|
179
183
|
for ipos in 0..<resQuery.count {
|
|
180
184
|
if let mName = resQuery[ipos]["name"] as? String {
|
|
181
185
|
triggers.append("\(mName)")
|
|
@@ -18,8 +18,10 @@ enum UtilsJsonError: Error {
|
|
|
18
18
|
case validateTriggers(message: String)
|
|
19
19
|
case validateViews(message: String)
|
|
20
20
|
case isLastModified(message: String)
|
|
21
|
-
|
|
21
|
+
case checkUpdate(message: String)
|
|
22
|
+
case checkValues(message: String)}
|
|
22
23
|
|
|
24
|
+
// swiftlint:disable file_length
|
|
23
25
|
// swiftlint:disable type_body_length
|
|
24
26
|
class UtilsJson {
|
|
25
27
|
|
|
@@ -38,9 +40,14 @@ class UtilsJson {
|
|
|
38
40
|
query.append(tableName)
|
|
39
41
|
query.append("';")
|
|
40
42
|
do {
|
|
41
|
-
|
|
43
|
+
var resQuery: [Any] = try UtilsSQLCipher
|
|
42
44
|
.querySQL(mDB: mDB, sql: query, values: [])
|
|
43
|
-
if resQuery.count > 0 {
|
|
45
|
+
if resQuery.count > 0 {
|
|
46
|
+
resQuery.removeFirst()
|
|
47
|
+
if resQuery.count == 1 {
|
|
48
|
+
ret = true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
44
51
|
} catch UtilsSQLCipherError.querySQL(let message) {
|
|
45
52
|
throw UtilsJsonError.tableNotExists(message: message)
|
|
46
53
|
}
|
|
@@ -89,9 +96,14 @@ class UtilsJson {
|
|
|
89
96
|
query.append(viewName)
|
|
90
97
|
query.append("';")
|
|
91
98
|
do {
|
|
92
|
-
|
|
99
|
+
var resQuery: [Any] = try UtilsSQLCipher
|
|
93
100
|
.querySQL(mDB: mDB, sql: query, values: [])
|
|
94
|
-
if resQuery.count > 0 {
|
|
101
|
+
if resQuery.count > 0 {
|
|
102
|
+
resQuery.removeFirst()
|
|
103
|
+
if resQuery.count == 1 {
|
|
104
|
+
ret = true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
95
107
|
} catch UtilsSQLCipherError.querySQL(let message) {
|
|
96
108
|
throw UtilsJsonError.viewNotExists(message: message)
|
|
97
109
|
}
|
|
@@ -109,8 +121,9 @@ class UtilsJson {
|
|
|
109
121
|
query.append(tableName)
|
|
110
122
|
query.append(");")
|
|
111
123
|
do {
|
|
112
|
-
|
|
124
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
113
125
|
if resQuery.count > 0 {
|
|
126
|
+
resQuery.removeFirst()
|
|
114
127
|
var names: [String] = []
|
|
115
128
|
var types: [String] = []
|
|
116
129
|
for ipos in 0..<resQuery.count {
|
|
@@ -190,9 +203,12 @@ class UtilsJson {
|
|
|
190
203
|
query.append("\(key);")
|
|
191
204
|
}
|
|
192
205
|
do {
|
|
193
|
-
|
|
194
|
-
if resQuery.count
|
|
195
|
-
|
|
206
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
207
|
+
if resQuery.count > 1 {
|
|
208
|
+
resQuery.removeFirst()
|
|
209
|
+
if resQuery.count == 1 {
|
|
210
|
+
ret = true
|
|
211
|
+
}
|
|
196
212
|
}
|
|
197
213
|
} catch DatabaseError.selectSQL(let message) {
|
|
198
214
|
throw UtilsJsonError.isIdExists(
|
|
@@ -224,6 +240,70 @@ class UtilsJson {
|
|
|
224
240
|
return retArray
|
|
225
241
|
}
|
|
226
242
|
|
|
243
|
+
// MARK: - ImportFromJson - CheckUpdate
|
|
244
|
+
|
|
245
|
+
// swiftlint:disable function_parameter_count
|
|
246
|
+
class func checkUpdate(mDB: Database, stmt: String, values: [Any],
|
|
247
|
+
tableName: String, names: [String],
|
|
248
|
+
types: [String]) throws -> Bool {
|
|
249
|
+
var isRun: Bool = true
|
|
250
|
+
if stmt.prefix(6) == "UPDATE" {
|
|
251
|
+
var query: String = "SELECT * FROM \(tableName) WHERE \(names[0]) = "
|
|
252
|
+
if type(of: values[0]) == String.self {
|
|
253
|
+
query.append("'\(values[0])';")
|
|
254
|
+
} else {
|
|
255
|
+
query.append("\(values[0]);")
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
do {
|
|
259
|
+
// create the table data
|
|
260
|
+
let resValues: [[Any]] = try ExportToJson
|
|
261
|
+
.createValues(mDB: mDB, query: query, names: names,
|
|
262
|
+
types: types)
|
|
263
|
+
if resValues.count > 0 {
|
|
264
|
+
isRun = try checkValues(values: values, nValues: resValues[0])
|
|
265
|
+
return isRun
|
|
266
|
+
} else {
|
|
267
|
+
let msg = "CheckUpdate statement returns nothing"
|
|
268
|
+
throw UtilsJsonError.checkUpdate(message: msg)
|
|
269
|
+
}
|
|
270
|
+
} catch ExportToJsonError.createValues(let message) {
|
|
271
|
+
throw UtilsJsonError.checkUpdate(message: message)
|
|
272
|
+
} catch UtilsJsonError.checkValues(let message) {
|
|
273
|
+
throw UtilsJsonError.checkUpdate(message: message)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return isRun
|
|
277
|
+
}
|
|
278
|
+
// swiftlint:enable function_parameter_count
|
|
279
|
+
|
|
280
|
+
// MARK: - ImportFromJson - CheckValues
|
|
281
|
+
|
|
282
|
+
class func checkValues(values: [Any], nValues: [Any]) throws -> Bool {
|
|
283
|
+
if values.count > 0 && nValues.count > 0
|
|
284
|
+
&& values.count == nValues.count {
|
|
285
|
+
let valuesWithIndex = values.enumerated()
|
|
286
|
+
for (index, mValue) in valuesWithIndex {
|
|
287
|
+
let rValue = nValues[index]
|
|
288
|
+
if type(of: rValue) == Double.self {
|
|
289
|
+
if let dValue = rValue as? Double {
|
|
290
|
+
if let dValues = mValue as? Double {
|
|
291
|
+
if !dValue.isEqual(to: dValues) {
|
|
292
|
+
return true
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
} else if rValue as AnyObject !== values[index] as AnyObject {
|
|
297
|
+
return true
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return false
|
|
301
|
+
} else {
|
|
302
|
+
let msg = "CheckValues Both arrays not the same length"
|
|
303
|
+
throw UtilsJsonError.checkValues(message: msg)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
}
|
|
227
307
|
// MARK: - ImportFromJson - SetNameForUpdate
|
|
228
308
|
|
|
229
309
|
class func setNameForUpdate(names: [String]) -> String {
|
|
@@ -360,3 +440,4 @@ class UtilsJson {
|
|
|
360
440
|
|
|
361
441
|
}
|
|
362
442
|
// swiftlint:enable type_body_length
|
|
443
|
+
// swiftlint:enable file_length
|
|
@@ -159,27 +159,6 @@ class UtilsSQLCipher {
|
|
|
159
159
|
let msg: String = "Cannot open the DB"
|
|
160
160
|
throw UtilsSQLCipherError.openOrCreateDatabase(message: msg)
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
/* this should work but doe not sqlite3_key_v2 is not known
|
|
164
|
-
if password.count > 0 {
|
|
165
|
-
let nKey:Int32 = Int32(password.count)
|
|
166
|
-
if sqlite3_key_v2(mDB!, filename, password, nKey) == SQLITE_OK {
|
|
167
|
-
var stmt: String = "SELECT count(*) FROM "
|
|
168
|
-
stmt.append("sqlite_master;")
|
|
169
|
-
if sqlite3_exec(mDB, stmt, nil, nil, nil) !=
|
|
170
|
-
SQLITE_OK {
|
|
171
|
-
print("Unable to open a database \(filename)")
|
|
172
|
-
throw UtilsSQLCipherError
|
|
173
|
-
.openOrCreateDatabase(message: msg)
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
print("Unable to open a database \(filename)")
|
|
177
|
-
throw UtilsSQLCipherError
|
|
178
|
-
.openOrCreateDatabase(message: msg)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
print("Successfully opened database \(filename)")
|
|
182
|
-
*/
|
|
183
162
|
return mDB
|
|
184
163
|
} else {
|
|
185
164
|
let message: String = "open_v2 failed"
|
|
@@ -266,10 +245,11 @@ class UtilsSQLCipher {
|
|
|
266
245
|
|
|
267
246
|
let sqltr: String = "PRAGMA user_version;"
|
|
268
247
|
do {
|
|
269
|
-
|
|
248
|
+
var resVersion = try UtilsSQLCipher.querySQL(mDB: mDB,
|
|
270
249
|
sql: sqltr,
|
|
271
250
|
values: [])
|
|
272
|
-
if resVersion.count >
|
|
251
|
+
if resVersion.count > 1 {
|
|
252
|
+
resVersion.removeFirst()
|
|
273
253
|
guard let res: Int64 = resVersion[0]["user_version"]
|
|
274
254
|
as? Int64 else {
|
|
275
255
|
throw UtilsSQLCipherError.getVersion(
|
|
@@ -504,10 +484,13 @@ class UtilsSQLCipher {
|
|
|
504
484
|
// MARK: - FetchColumnInfo
|
|
505
485
|
|
|
506
486
|
// swiftlint:disable function_body_length
|
|
487
|
+
// swiftlint:disable cyclomatic_complexity
|
|
507
488
|
class func fetchColumnInfo(handle: OpaquePointer?)
|
|
508
489
|
throws -> [[String: Any]] {
|
|
509
490
|
var result: [[String: Any]] = []
|
|
510
491
|
var columnCount: Int32 = 0
|
|
492
|
+
var columnNames: [String] = []
|
|
493
|
+
var columnData: [String: Any] = [:]
|
|
511
494
|
|
|
512
495
|
while sqlite3_step(handle) == SQLITE_ROW {
|
|
513
496
|
columnCount = sqlite3_column_count(handle)
|
|
@@ -521,6 +504,13 @@ class UtilsSQLCipher {
|
|
|
521
504
|
throw UtilsSQLCipherError
|
|
522
505
|
.fetchColumnInfo(message: message)
|
|
523
506
|
}
|
|
507
|
+
if columnNames.count <= columnCount {
|
|
508
|
+
columnNames.append(String(cString: name))
|
|
509
|
+
if columnNames.count == columnCount {
|
|
510
|
+
columnData["ios_columns"] = columnNames
|
|
511
|
+
result.append(columnData)
|
|
512
|
+
}
|
|
513
|
+
}
|
|
524
514
|
switch sqlite3_column_type(handle, Int32(index)) {
|
|
525
515
|
case SQLITE_INTEGER:
|
|
526
516
|
let val: Int64 = sqlite3_column_int64(handle, index)
|
|
@@ -558,6 +548,7 @@ class UtilsSQLCipher {
|
|
|
558
548
|
}
|
|
559
549
|
return result
|
|
560
550
|
}
|
|
551
|
+
// swiftlint:enable cyclomatic_complexity
|
|
561
552
|
// swiftlint:enable function_body_length
|
|
562
553
|
|
|
563
554
|
// MARK: - dbChanges
|
|
@@ -307,9 +307,10 @@ class UtilsUpgrade {
|
|
|
307
307
|
var retNames: [String] = []
|
|
308
308
|
let query: String = "PRAGMA table_info('\(tableName)');"
|
|
309
309
|
do {
|
|
310
|
-
|
|
310
|
+
var resColumns: [[String: Any]] = try
|
|
311
311
|
mDB.selectSQL(sql: query, values: [])
|
|
312
312
|
if resColumns.count > 0 {
|
|
313
|
+
resColumns.removeFirst()
|
|
313
314
|
for rColumn in resColumns {
|
|
314
315
|
guard let columnName: String = rColumn["name"] as?
|
|
315
316
|
String else {
|
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
|
"description": "Community plugin for native & electron SQLite databases",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typescript": "~4.0.5"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@capacitor/core": "~3.4.
|
|
77
|
+
"@capacitor/core": "~3.4.2"
|
|
78
78
|
},
|
|
79
79
|
"prettier": "@ionic/prettier-config",
|
|
80
80
|
"swiftlint": "@ionic/swiftlint-config",
|
|
@@ -93,6 +93,6 @@
|
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"jeep-sqlite": "^1.4.
|
|
96
|
+
"jeep-sqlite": "^1.4.1"
|
|
97
97
|
}
|
|
98
98
|
}
|