diff --git a/ios/Plugin/CapacitorSQLite.swift b/ios/Plugin/CapacitorSQLite.swift index c0fdc89d..f18979da 100644 --- a/ios/Plugin/CapacitorSQLite.swift +++ b/ios/Plugin/CapacitorSQLite.swift @@ -247,7 +247,7 @@ enum CapacitorSQLiteError: Error { // MARK: - CheckEncryptionSecret - @objc public func checkEncryptionSecret(passphrase: String) throws -> NSNumber { + @objc public func checkEncryptionSecret(passphrase: String) throws -> NSNumber { guard isInit else { throw CapacitorSQLiteError.failed(message: initMessage) } @@ -557,7 +557,7 @@ enum CapacitorSQLiteError: Error { // MARK: - GetVersion @objc public func getVersion(_ dbName: String, readonly: Bool) - throws -> NSNumber { + throws -> NSNumber { guard isInit else { throw CapacitorSQLiteError.failed(message: initMessage) } @@ -585,7 +585,7 @@ enum CapacitorSQLiteError: Error { UtilsDownloadFromHTTP.download(databaseLocation: databaseLocation, url: url) { ( result) in switch result { - case .success(_): + case .success: self.retHandler.rResult(call: call) return case .failure(let error): @@ -624,7 +624,7 @@ enum CapacitorSQLiteError: Error { @objc public func checkConnectionsConsistency(_ dbNames: [String], openModes: [String]) - throws -> NSNumber { + throws -> NSNumber { guard isInit else { throw CapacitorSQLiteError.failed(message: initMessage) } @@ -1033,7 +1033,7 @@ enum CapacitorSQLiteError: Error { account: account) if !isEncryption && (state.rawValue == "ENCRYPTEDGLOBALSECRET" || - state.rawValue == "ENCRYPTEDSECRET") { + state.rawValue == "ENCRYPTEDSECRET") { var msg = "Cannot delete an Encrypted database with " msg += "No Encryption set in capacitor.config" throw CapacitorSQLiteError.failed(message: msg) diff --git a/ios/Plugin/Database.swift b/ios/Plugin/Database.swift index 651b260a..dce49833 100644 --- a/ios/Plugin/Database.swift +++ b/ios/Plugin/Database.swift @@ -214,7 +214,7 @@ class Database { let msg: String = "Failed in deleteBackupDB \(message)" throw DatabaseError.open(message: msg) } catch UtilsUpgradeError.onUpgradeFailed(let message) { - //restore the database + // restore the database do { try UtilsSQLCipher .restoreDB(databaseLocation: databaseLocation, diff --git a/ios/Plugin/ImportExportJson/ExportToJson.swift b/ios/Plugin/ImportExportJson/ExportToJson.swift index 2279629a..8ae930c7 100644 --- a/ios/Plugin/ImportExportJson/ExportToJson.swift +++ b/ios/Plugin/ImportExportJson/ExportToJson.swift @@ -231,7 +231,7 @@ class ExportToJson { } switch expMode { - case "partial" : + case "partial": tables = try ExportToJson .getTablesPartial(mDB: mDB, resTables: resTables) @@ -1199,9 +1199,9 @@ class ExportToJson { row.append(val) } else if values[pos][names[jpos]] is Int64 && ( INTEGERAFFINITY.contains(types[jpos].uppercased()) || - INTEGERAFFINITY.contains(types[jpos] - .components(separatedBy: "(")[0].uppercased()) || - NUMERICAFFINITY.contains(types[jpos].uppercased())) { + INTEGERAFFINITY.contains(types[jpos] + .components(separatedBy: "(")[0].uppercased()) || + NUMERICAFFINITY.contains(types[jpos].uppercased())) { guard let val = values[pos][names[jpos]] as? Int64 else { throw ExportToJsonError.createValues( @@ -1210,8 +1210,8 @@ class ExportToJson { row.append(val) } else if values[pos][names[jpos]] is Int64 && ( REALAFFINITY.contains(types[jpos].uppercased()) || - NUMERICAFFINITY.contains(types[jpos] - .components(separatedBy: "(")[0].uppercased())) { + NUMERICAFFINITY.contains(types[jpos] + .components(separatedBy: "(")[0].uppercased())) { guard let val = values[pos][names[jpos]] as? Int64 else { throw ExportToJsonError.createValues( @@ -1221,7 +1221,7 @@ class ExportToJson { } else if values[pos][names[jpos]] is Double && ( REALAFFINITY.contains(types[jpos].uppercased()) || NUMERICAFFINITY.contains(types[jpos] - .components(separatedBy: "(")[0].uppercased())) { + .components(separatedBy: "(")[0].uppercased())) { guard let val = values[pos][names[jpos]] as? Double else { throw ExportToJsonError.createValues( diff --git a/ios/Plugin/Models/KeychainServices.swift b/ios/Plugin/Models/KeychainServices.swift index bd566e84..b1b43bab 100644 --- a/ios/Plugin/Models/KeychainServices.swift +++ b/ios/Plugin/Models/KeychainServices.swift @@ -114,7 +114,7 @@ class KeychainWrapper { throw KeychainWrapperError(type: .unableToConvertToString) } - //5 + // 5 return value } diff --git a/ios/Plugin/Utils/UtilsBinding.swift b/ios/Plugin/Utils/UtilsBinding.swift index 88d61d3a..dd9fddd9 100644 --- a/ios/Plugin/Utils/UtilsBinding.swift +++ b/ios/Plugin/Utils/UtilsBinding.swift @@ -74,7 +74,7 @@ class UtilsBinding { let sortedValues = extractSortedValues(from: dict) let data: Data = Data(sortedValues) sqlite3_bind_blob(handle, Int32(idx), data.bytes, - Int32(data.bytes.count), SQLITETRANSIENT) + Int32(data.bytes.count), SQLITETRANSIENT) } } else { throw UtilsSQLCipherError.bindFailed @@ -95,5 +95,5 @@ class UtilsBinding { return false } return true - } + } } diff --git a/ios/Plugin/Utils/UtilsDelete.swift b/ios/Plugin/Utils/UtilsDelete.swift index 835ad750..e25e68a9 100644 --- a/ios/Plugin/Utils/UtilsDelete.swift +++ b/ios/Plugin/Utils/UtilsDelete.swift @@ -125,7 +125,7 @@ class UtilsDelete { // update all related element // set sql_deleted = 1 and last_modified // tableName - //update all by sending return true + // update all by sending return true results = try upDateWhereForCascade( results: result) @@ -342,7 +342,7 @@ class UtilsDelete { colNames: [String], values: [Any]) throws { var lastId: Int64 = -1 - //update sql_deleted for this references + // update sql_deleted for this references let stmt = "UPDATE \(tableName) SET \(setStmt) \(whereStmt)" var selValues: [Any] = [] if !values.isEmpty { @@ -450,8 +450,8 @@ class UtilsDelete { throw UtilsDeleteError.getRefs(message: msg) } } else { - let msg = "getRefs: Error creating tableNameMatch " - throw UtilsDeleteError.getRefs(message: msg) + let msg = "getRefs: Error creating tableNameMatch " + throw UtilsDeleteError.getRefs(message: msg) } // Regular expression pattern to match the FOREIGN KEY diff --git a/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift b/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift index 4c9d3bf5..12bd71d2 100644 --- a/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +++ b/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift @@ -21,8 +21,8 @@ class UtilsDownloadFromHTTP { class func download(databaseLocation: String, url: String, completion: @escaping (Result) -> Void) { guard let fileDetails = getFileDetails(url: url), - let fileExtension = fileDetails.extension , - fileExtension == "db" || fileExtension == "zip" else { + let fileExtension = fileDetails.extension, + fileExtension == "db" || fileExtension == "zip" else { let msg = "download: Not a .zip or .db url" print("\(msg)") completion(.failure(UtilsDownloadError.downloadFromHTTPFailed(message: msg))) diff --git a/ios/Plugin/Utils/UtilsDrop.swift b/ios/Plugin/Utils/UtilsDrop.swift index 1c583aad..03d78160 100644 --- a/ios/Plugin/Utils/UtilsDrop.swift +++ b/ios/Plugin/Utils/UtilsDrop.swift @@ -192,7 +192,7 @@ class UtilsDrop { .getTriggersNamesFailed(message: message) } } - //1234567890123456789012345678901234567890123456789012345678901234567890 + // 1234567890123456789012345678901234567890123456789012345678901234567890 // MARK: - dropTriggers class func dropTriggers(mDB: Database) throws -> Int { diff --git a/ios/Plugin/Utils/UtilsSQLCipher.swift b/ios/Plugin/Utils/UtilsSQLCipher.swift index d571263c..772bf438 100644 --- a/ios/Plugin/Utils/UtilsSQLCipher.swift +++ b/ios/Plugin/Utils/UtilsSQLCipher.swift @@ -456,9 +456,9 @@ class UtilsSQLCipher { var result: [[String: Any]] = [] var retMode: String let stmtType = sqlStmt - .trimmingCharacters(in: .whitespacesAndNewlines) - .components(separatedBy: " ") - .first?.capitalized ?? "" + .trimmingCharacters(in: .whitespacesAndNewlines) + .components(separatedBy: " ") + .first?.capitalized ?? "" if #available(iOS 15, *) { retMode = returnMode @@ -570,9 +570,9 @@ class UtilsSQLCipher { var result: [[String: Any]] = [] let initLastId = Int64(sqlite3_last_insert_rowid(mDB.mDb)) let stmtType = sqlStmt - .trimmingCharacters(in: .whitespacesAndNewlines) - .components(separatedBy: " ") - .first?.capitalized ?? "" + .trimmingCharacters(in: .whitespacesAndNewlines) + .components(separatedBy: " ") + .first?.capitalized ?? "" if stmtType == "DELETE" && names.count > 0 { @@ -986,17 +986,17 @@ class UtilsSQLCipher { } } } else { - let resp = try UtilsSQLCipher - .prepareSQL(mDB: mDB, sql: sql, values: values, - fromJson: false, returnMode: returnMode) - lastId = resp.0 - respSet = resp.1 - if lastId == -1 { - let message: String = "lastId < 0" - throw UtilsSQLCipherError.executeSet( - message: message) - } - response = addToResponse(response: response, respSet: respSet) + let resp = try UtilsSQLCipher + .prepareSQL(mDB: mDB, sql: sql, values: values, + fromJson: false, returnMode: returnMode) + lastId = resp.0 + respSet = resp.1 + if lastId == -1 { + let message: String = "lastId < 0" + throw UtilsSQLCipherError.executeSet( + message: message) + } + response = addToResponse(response: response, respSet: respSet) } } diff --git a/ios/Plugin/Utils/UtilsSQLStatement.swift b/ios/Plugin/Utils/UtilsSQLStatement.swift index 846669f7..91022ae1 100644 --- a/ios/Plugin/Utils/UtilsSQLStatement.swift +++ b/ios/Plugin/Utils/UtilsSQLStatement.swift @@ -104,8 +104,8 @@ class UtilsSQLStatement { } } class func modifyPair(_ pair: String, from: [String], - destination: [String],prefix: String) throws -> String { - + destination: [String], prefix: String) throws -> String { + let pattern = #"(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)"# guard let range = pair.range(of: pattern, options: .regularExpression) else { @@ -159,79 +159,79 @@ class UtilsSQLStatement { let modifiedColumn = "\(prefix)\(newColumn)" return "\(modifiedColumn) \(mOperator) \(value)" } -/* - class func addPrefixToWhereClause(_ whereClause: String, - from: [String], - destination: [String], prefix: String) - throws -> String { - var columnValuePairs: [String] - if whereClause.contains("AND") { - if #available(iOS 16.0, *) { - let subSequenceArray = whereClause.split(separator: "AND") - columnValuePairs = subSequenceArray.map({ String($0) }) - } else { - columnValuePairs = whereClause - .components(separatedBy: "AND") - } - } else { - columnValuePairs = [whereClause] - } - let modifiedPairs = try columnValuePairs.map({ pair -> String in - let pattern = #"(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)"# - - if let range = pair.range(of: pattern, options: .regularExpression) { - let match = String(pair[range]) - let regex = try NSRegularExpression(pattern: pattern) - let matchRange = NSRange(match.startIndex..., in: match) - - if let matchResult = regex.firstMatch(in: match, range: matchRange) { - - guard let columnRange = Range(matchResult.range(at: 1), in: match) else { - let msg = "addPrefixToWhereClause: " + - "columnRange failed " - throw UtilsSQLStatementError - .addPrefixToWhereClause(message: msg) - } - guard let operatorRange = Range(matchResult.range(at: 2), in: match) else { - let msg = "addPrefixToWhereClause: " + - "operatorRange failed " - throw UtilsSQLStatementError - .addPrefixToWhereClause(message: msg) - } - guard let valueRange = Range(matchResult.range(at: 3), in: match) else { - let msg = "addPrefixToWhereClause: " + - "valueRange failed " - throw UtilsSQLStatementError - .addPrefixToWhereClause(message: msg) - } - - let column = String(match[columnRange]).trimmingCharacters(in: .whitespacesAndNewlines) - let mOperator = String(match[operatorRange]).trimmingCharacters(in: .whitespacesAndNewlines) - let value = String(match[valueRange]).trimmingCharacters(in: .whitespacesAndNewlines) - - var newColumn = column - if let index = UtilsSQLStatement - .findIndexOfStringInArray(column, destination), index != -1 { - guard let mNewColumn = UtilsSQLStatement - .getStringAtIndex(from, index) else { - let msg = "addPrefixToWhereClause: index " + - "mistmatch " - throw UtilsSQLStatementError - .addPrefixToWhereClause(message: msg) - } - newColumn = mNewColumn - } - - let modifiedColumn = "\(prefix)\(newColumn)" - return "\(modifiedColumn) \(mOperator) \(value)" - } - } - return pair - }) - return modifiedPairs.joined(separator: " AND ") - - } -*/ + /* + class func addPrefixToWhereClause(_ whereClause: String, + from: [String], + destination: [String], prefix: String) + throws -> String { + var columnValuePairs: [String] + if whereClause.contains("AND") { + if #available(iOS 16.0, *) { + let subSequenceArray = whereClause.split(separator: "AND") + columnValuePairs = subSequenceArray.map({ String($0) }) + } else { + columnValuePairs = whereClause + .components(separatedBy: "AND") + } + } else { + columnValuePairs = [whereClause] + } + let modifiedPairs = try columnValuePairs.map({ pair -> String in + let pattern = #"(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)"# + + if let range = pair.range(of: pattern, options: .regularExpression) { + let match = String(pair[range]) + let regex = try NSRegularExpression(pattern: pattern) + let matchRange = NSRange(match.startIndex..., in: match) + + if let matchResult = regex.firstMatch(in: match, range: matchRange) { + + guard let columnRange = Range(matchResult.range(at: 1), in: match) else { + let msg = "addPrefixToWhereClause: " + + "columnRange failed " + throw UtilsSQLStatementError + .addPrefixToWhereClause(message: msg) + } + guard let operatorRange = Range(matchResult.range(at: 2), in: match) else { + let msg = "addPrefixToWhereClause: " + + "operatorRange failed " + throw UtilsSQLStatementError + .addPrefixToWhereClause(message: msg) + } + guard let valueRange = Range(matchResult.range(at: 3), in: match) else { + let msg = "addPrefixToWhereClause: " + + "valueRange failed " + throw UtilsSQLStatementError + .addPrefixToWhereClause(message: msg) + } + + let column = String(match[columnRange]).trimmingCharacters(in: .whitespacesAndNewlines) + let mOperator = String(match[operatorRange]).trimmingCharacters(in: .whitespacesAndNewlines) + let value = String(match[valueRange]).trimmingCharacters(in: .whitespacesAndNewlines) + + var newColumn = column + if let index = UtilsSQLStatement + .findIndexOfStringInArray(column, destination), index != -1 { + guard let mNewColumn = UtilsSQLStatement + .getStringAtIndex(from, index) else { + let msg = "addPrefixToWhereClause: index " + + "mistmatch " + throw UtilsSQLStatementError + .addPrefixToWhereClause(message: msg) + } + newColumn = mNewColumn + } + + let modifiedColumn = "\(prefix)\(newColumn)" + return "\(modifiedColumn) \(mOperator) \(value)" + } + } + return pair + }) + return modifiedPairs.joined(separator: " AND ") + + } + */ // MARK: - findIndexOfStringInArray class func findIndexOfStringInArray(_ target: String, _ array: [String]) -> Int? { @@ -376,48 +376,48 @@ class UtilsSQLStatement { } } -/* func processToken(_ token: String) { - if token.uppercased() == "IN" { - inClause = true - } else if inClause && (token.prefix(7).uppercased() == "(VALUES" || - token.prefix(8).uppercased() == "( VALUES") { - inValues = true - } else if inValues && (token.suffix(2).uppercased() == "))" || - token.suffix(3).uppercased() == ") )") { - inValues = false - } else if inClause && !inValues && token.prefix(1) == "(" { - inPar = true - } else if inClause && !inValues && token.suffix(1) == ")" { - inPar = false - inClause = false - } else if token.uppercased() == "BETWEEN" { - betweenClause = true - } else if betweenClause && token.uppercased() == "AND" { - andClause = true - } else if operators.contains(token) { - inOper = true - } else if token.uppercased() == "LIKE" { - inLike = true - } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil - && !inClause && (!inValues || !inPar) - && !betweenClause && !andClause && !inOper && !inLike - && !keywords.contains(token.uppercased()) { - var mToken = extractString(from: token) - mToken = removeOperatorsAndFollowing(from: mToken) - columns.append(mToken) - } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil - && betweenClause && andClause { - betweenClause = false - andClause = false - } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil - && inOper { - inOper = false - } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil - && inLike { - inLike = false - } - } - */ + /* func processToken(_ token: String) { + if token.uppercased() == "IN" { + inClause = true + } else if inClause && (token.prefix(7).uppercased() == "(VALUES" || + token.prefix(8).uppercased() == "( VALUES") { + inValues = true + } else if inValues && (token.suffix(2).uppercased() == "))" || + token.suffix(3).uppercased() == ") )") { + inValues = false + } else if inClause && !inValues && token.prefix(1) == "(" { + inPar = true + } else if inClause && !inValues && token.suffix(1) == ")" { + inPar = false + inClause = false + } else if token.uppercased() == "BETWEEN" { + betweenClause = true + } else if betweenClause && token.uppercased() == "AND" { + andClause = true + } else if operators.contains(token) { + inOper = true + } else if token.uppercased() == "LIKE" { + inLike = true + } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil + && !inClause && (!inValues || !inPar) + && !betweenClause && !andClause && !inOper && !inLike + && !keywords.contains(token.uppercased()) { + var mToken = extractString(from: token) + mToken = removeOperatorsAndFollowing(from: mToken) + columns.append(mToken) + } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil + && betweenClause && andClause { + betweenClause = false + andClause = false + } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil + && inOper { + inOper = false + } else if token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil + && inLike { + inLike = false + } + } + */ // swiftlint:disable cyclomatic_complexity func processToken(_ token: String) { if token.uppercased() == "IN" { @@ -538,7 +538,7 @@ class UtilsSQLStatement { } class func processInsertStatement(_ sqlStmt: String, stmt: String) -> SQLStatementInfo { if let valuesIndex = stmt.range(of: "VALUES", options: .caseInsensitive)?.lowerBound, - let closingParenthesisIndex = stmt + let closingParenthesisIndex = stmt .range(of: ")", options: .backwards, range: valuesIndex..