@capacitor-community/sqlite 3.4.2-2 → 3.4.2-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +42 -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 +63 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1227 -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/ExportToJson.swift +27 -12
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +6 -3
- package/ios/Plugin/ImportExportJson/JsonSQLite.swift +6 -0
- package/ios/Plugin/Utils/UtilsBinding.swift +2 -2
- package/ios/Plugin/Utils/UtilsDrop.swift +8 -4
- package/ios/Plugin/Utils/UtilsJson.swift +22 -8
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +14 -2
- package/ios/Plugin/Utils/UtilsUpgrade.swift +2 -1
- 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 {
|
|
@@ -72,9 +72,10 @@ class ExportToJson {
|
|
|
72
72
|
// get the view's name
|
|
73
73
|
var stmtV: String = "SELECT name,sql FROM sqlite_master WHERE "
|
|
74
74
|
stmtV.append("type = 'view' AND name NOT LIKE 'sqlite_%';")
|
|
75
|
-
|
|
75
|
+
var resViews = try UtilsSQLCipher.querySQL(
|
|
76
76
|
mDB: mDB, sql: stmtV, values: [])
|
|
77
|
-
if resViews.count >
|
|
77
|
+
if resViews.count > 1 {
|
|
78
|
+
resViews.removeFirst()
|
|
78
79
|
views = try ExportToJson
|
|
79
80
|
.getViews(mDB: mDB,
|
|
80
81
|
resViews: resViews)
|
|
@@ -85,9 +86,10 @@ class ExportToJson {
|
|
|
85
86
|
var query: String = "SELECT name,sql FROM sqlite_master WHERE "
|
|
86
87
|
query.append("type = 'table' AND name NOT LIKE 'sqlite_%' ")
|
|
87
88
|
query.append("AND name NOT LIKE 'sync_table';")
|
|
88
|
-
|
|
89
|
+
var resTables = try UtilsSQLCipher.querySQL(
|
|
89
90
|
mDB: mDB, sql: query, values: [])
|
|
90
|
-
if resTables.count >
|
|
91
|
+
if resTables.count > 1 {
|
|
92
|
+
resTables.removeFirst()
|
|
91
93
|
let isExists: Bool = try UtilsJson.isTableExists(
|
|
92
94
|
mDB: mDB, tableName: "sync_table")
|
|
93
95
|
if !isExists && expMode == "partial" {
|
|
@@ -528,9 +530,10 @@ class ExportToJson {
|
|
|
528
530
|
var ret: Int64 = -1
|
|
529
531
|
let query: String = "SELECT sync_date FROM sync_table;"
|
|
530
532
|
do {
|
|
531
|
-
|
|
533
|
+
var resSyncDate = try UtilsSQLCipher.querySQL(
|
|
532
534
|
mDB: mDB, sql: query, values: [])
|
|
533
|
-
if resSyncDate.count >
|
|
535
|
+
if resSyncDate.count > 1 {
|
|
536
|
+
resSyncDate.removeFirst()
|
|
534
537
|
guard let res: Int64 = resSyncDate[0]["sync_date"] as?
|
|
535
538
|
Int64 else {
|
|
536
539
|
throw ExportToJsonError.getSyncDate(
|
|
@@ -548,6 +551,7 @@ class ExportToJson {
|
|
|
548
551
|
// MARK: - ExportToJson - GetTablesModified
|
|
549
552
|
|
|
550
553
|
// swiftlint:disable function_body_length
|
|
554
|
+
// swiftlint:disable cyclomatic_complexity
|
|
551
555
|
class func getTablesModified(mDB: Database,
|
|
552
556
|
tables: [[String: Any]],
|
|
553
557
|
syncDate: Int64)
|
|
@@ -569,6 +573,9 @@ class ExportToJson {
|
|
|
569
573
|
do {
|
|
570
574
|
var resQuery = try UtilsSQLCipher.querySQL(
|
|
571
575
|
mDB: mDB, sql: query, values: [])
|
|
576
|
+
if resQuery.count > 1 {
|
|
577
|
+
resQuery.removeFirst()
|
|
578
|
+
}
|
|
572
579
|
if resQuery.count != 1 {
|
|
573
580
|
break
|
|
574
581
|
} else {
|
|
@@ -585,6 +592,9 @@ class ExportToJson {
|
|
|
585
592
|
query.append("\(syncDate);")
|
|
586
593
|
resQuery = try UtilsSQLCipher.querySQL(
|
|
587
594
|
mDB: mDB, sql: query, values: [])
|
|
595
|
+
if resQuery.count > 1 {
|
|
596
|
+
resQuery.removeFirst()
|
|
597
|
+
}
|
|
588
598
|
if resQuery.count != 1 {
|
|
589
599
|
break
|
|
590
600
|
} else {
|
|
@@ -618,6 +628,8 @@ class ExportToJson {
|
|
|
618
628
|
}
|
|
619
629
|
return retObj
|
|
620
630
|
}
|
|
631
|
+
// swiftlint:enable cyclomatic_complexity
|
|
632
|
+
// swiftlint:enable function_body_length
|
|
621
633
|
|
|
622
634
|
// MARK: - ExportToJson - ModEmbeddedParentheses
|
|
623
635
|
|
|
@@ -751,9 +763,10 @@ class ExportToJson {
|
|
|
751
763
|
query.append("type = 'index' AND tbl_name = '\(tableName)' ")
|
|
752
764
|
query.append("AND sql NOTNULL;")
|
|
753
765
|
do {
|
|
754
|
-
|
|
766
|
+
var resIndexes = try UtilsSQLCipher.querySQL(
|
|
755
767
|
mDB: mDB, sql: query, values: [])
|
|
756
|
-
if resIndexes.count >
|
|
768
|
+
if resIndexes.count > 1 {
|
|
769
|
+
resIndexes.removeFirst()
|
|
757
770
|
for ipos in 0..<resIndexes.count {
|
|
758
771
|
var row: [String: String] = [:]
|
|
759
772
|
let keys: [String] = Array(resIndexes[ipos].keys)
|
|
@@ -837,9 +850,10 @@ class ExportToJson {
|
|
|
837
850
|
query.append("type = 'trigger' AND tbl_name = '\(tableName)' ")
|
|
838
851
|
query.append("AND sql NOTNULL;")
|
|
839
852
|
do {
|
|
840
|
-
|
|
853
|
+
var resTriggers = try UtilsSQLCipher.querySQL(
|
|
841
854
|
mDB: mDB, sql: query, values: [])
|
|
842
|
-
if resTriggers.count >
|
|
855
|
+
if resTriggers.count > 1 {
|
|
856
|
+
resTriggers.removeFirst()
|
|
843
857
|
for ipos in 0..<resTriggers.count {
|
|
844
858
|
var row: [String: String] = [:]
|
|
845
859
|
let keys: [String] = Array(resTriggers[ipos].keys)
|
|
@@ -952,9 +966,10 @@ class ExportToJson {
|
|
|
952
966
|
|
|
953
967
|
var retValues: [[Any]] = []
|
|
954
968
|
do {
|
|
955
|
-
|
|
969
|
+
var resValues = try UtilsSQLCipher.querySQL(
|
|
956
970
|
mDB: mDB, sql: query, values: [])
|
|
957
|
-
if resValues.count >
|
|
971
|
+
if resValues.count > 1 {
|
|
972
|
+
resValues.removeFirst()
|
|
958
973
|
for ipos in 0..<resValues.count {
|
|
959
974
|
var row: [Any] = []
|
|
960
975
|
do {
|
|
@@ -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) ")
|
|
@@ -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)")
|
|
@@ -38,9 +38,14 @@ class UtilsJson {
|
|
|
38
38
|
query.append(tableName)
|
|
39
39
|
query.append("';")
|
|
40
40
|
do {
|
|
41
|
-
|
|
41
|
+
var resQuery: [Any] = try UtilsSQLCipher
|
|
42
42
|
.querySQL(mDB: mDB, sql: query, values: [])
|
|
43
|
-
if resQuery.count > 0 {
|
|
43
|
+
if resQuery.count > 0 {
|
|
44
|
+
resQuery.removeFirst()
|
|
45
|
+
if resQuery.count == 1 {
|
|
46
|
+
ret = true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
44
49
|
} catch UtilsSQLCipherError.querySQL(let message) {
|
|
45
50
|
throw UtilsJsonError.tableNotExists(message: message)
|
|
46
51
|
}
|
|
@@ -89,9 +94,14 @@ class UtilsJson {
|
|
|
89
94
|
query.append(viewName)
|
|
90
95
|
query.append("';")
|
|
91
96
|
do {
|
|
92
|
-
|
|
97
|
+
var resQuery: [Any] = try UtilsSQLCipher
|
|
93
98
|
.querySQL(mDB: mDB, sql: query, values: [])
|
|
94
|
-
if resQuery.count > 0 {
|
|
99
|
+
if resQuery.count > 0 {
|
|
100
|
+
resQuery.removeFirst()
|
|
101
|
+
if resQuery.count == 1 {
|
|
102
|
+
ret = true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
95
105
|
} catch UtilsSQLCipherError.querySQL(let message) {
|
|
96
106
|
throw UtilsJsonError.viewNotExists(message: message)
|
|
97
107
|
}
|
|
@@ -109,8 +119,9 @@ class UtilsJson {
|
|
|
109
119
|
query.append(tableName)
|
|
110
120
|
query.append(");")
|
|
111
121
|
do {
|
|
112
|
-
|
|
122
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
113
123
|
if resQuery.count > 0 {
|
|
124
|
+
resQuery.removeFirst()
|
|
114
125
|
var names: [String] = []
|
|
115
126
|
var types: [String] = []
|
|
116
127
|
for ipos in 0..<resQuery.count {
|
|
@@ -190,9 +201,12 @@ class UtilsJson {
|
|
|
190
201
|
query.append("\(key);")
|
|
191
202
|
}
|
|
192
203
|
do {
|
|
193
|
-
|
|
194
|
-
if resQuery.count
|
|
195
|
-
|
|
204
|
+
var resQuery = try mDB.selectSQL(sql: query, values: [])
|
|
205
|
+
if resQuery.count > 1 {
|
|
206
|
+
resQuery.removeFirst()
|
|
207
|
+
if resQuery.count == 1 {
|
|
208
|
+
ret = true
|
|
209
|
+
}
|
|
196
210
|
}
|
|
197
211
|
} catch DatabaseError.selectSQL(let message) {
|
|
198
212
|
throw UtilsJsonError.isIdExists(
|
|
@@ -266,10 +266,11 @@ class UtilsSQLCipher {
|
|
|
266
266
|
|
|
267
267
|
let sqltr: String = "PRAGMA user_version;"
|
|
268
268
|
do {
|
|
269
|
-
|
|
269
|
+
var resVersion = try UtilsSQLCipher.querySQL(mDB: mDB,
|
|
270
270
|
sql: sqltr,
|
|
271
271
|
values: [])
|
|
272
|
-
if resVersion.count >
|
|
272
|
+
if resVersion.count > 1 {
|
|
273
|
+
resVersion.removeFirst()
|
|
273
274
|
guard let res: Int64 = resVersion[0]["user_version"]
|
|
274
275
|
as? Int64 else {
|
|
275
276
|
throw UtilsSQLCipherError.getVersion(
|
|
@@ -504,10 +505,13 @@ class UtilsSQLCipher {
|
|
|
504
505
|
// MARK: - FetchColumnInfo
|
|
505
506
|
|
|
506
507
|
// swiftlint:disable function_body_length
|
|
508
|
+
// swiftlint:disable cyclomatic_complexity
|
|
507
509
|
class func fetchColumnInfo(handle: OpaquePointer?)
|
|
508
510
|
throws -> [[String: Any]] {
|
|
509
511
|
var result: [[String: Any]] = []
|
|
510
512
|
var columnCount: Int32 = 0
|
|
513
|
+
var columnNames: [String] = []
|
|
514
|
+
var columnData: [String: Any] = [:]
|
|
511
515
|
|
|
512
516
|
while sqlite3_step(handle) == SQLITE_ROW {
|
|
513
517
|
columnCount = sqlite3_column_count(handle)
|
|
@@ -521,6 +525,13 @@ class UtilsSQLCipher {
|
|
|
521
525
|
throw UtilsSQLCipherError
|
|
522
526
|
.fetchColumnInfo(message: message)
|
|
523
527
|
}
|
|
528
|
+
if columnNames.count <= columnCount {
|
|
529
|
+
columnNames.append(String(cString: name))
|
|
530
|
+
if columnNames.count == columnCount {
|
|
531
|
+
columnData["ios_columns"] = columnNames
|
|
532
|
+
result.append(columnData)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
524
535
|
switch sqlite3_column_type(handle, Int32(index)) {
|
|
525
536
|
case SQLITE_INTEGER:
|
|
526
537
|
let val: Int64 = sqlite3_column_int64(handle, index)
|
|
@@ -558,6 +569,7 @@ class UtilsSQLCipher {
|
|
|
558
569
|
}
|
|
559
570
|
return result
|
|
560
571
|
}
|
|
572
|
+
// swiftlint:enable cyclomatic_complexity
|
|
561
573
|
// swiftlint:enable function_body_length
|
|
562
574
|
|
|
563
575
|
// 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-5",
|
|
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
|
}
|