@capacitor-community/sqlite 5.7.2 → 5.7.3-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 +3 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDownloadFromHTTP.java +71 -46
- package/electron/dist/plugin.js +37 -27
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +13 -12
- package/ios/Plugin/CapacitorSQLitePlugin.swift +9 -14
- package/ios/Plugin/Utils/UtilsBinding.swift +2 -3
- package/ios/Plugin/Utils/UtilsDelete.swift +25 -12
- package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +168 -98
- package/ios/Plugin/Utils/UtilsJson.swift +6 -6
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +4 -4
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +284 -90
- package/package.json +7 -7
|
@@ -11,6 +11,11 @@ enum UtilsSQLStatementError: Error {
|
|
|
11
11
|
case addPrefixToWhereClause(message: String)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
struct SQLStatementInfo {
|
|
15
|
+
let isReturning: Bool
|
|
16
|
+
let stmtString: String
|
|
17
|
+
let resultString: String
|
|
18
|
+
}
|
|
14
19
|
// swiftlint:disable file_length
|
|
15
20
|
// swiftlint:disable type_body_length
|
|
16
21
|
class UtilsSQLStatement {
|
|
@@ -69,13 +74,101 @@ class UtilsSQLStatement {
|
|
|
69
74
|
|
|
70
75
|
class func addPrefixToWhereClause(_ whereClause: String,
|
|
71
76
|
from: [String],
|
|
72
|
-
|
|
77
|
+
destination: [String], prefix: String)
|
|
78
|
+
throws -> String {
|
|
79
|
+
let columnValuePairs = getColumnValuePairs(from: from, destination: destination, whereClause: whereClause)
|
|
80
|
+
|
|
81
|
+
let modifiedPairs = try columnValuePairs.map({ pair in
|
|
82
|
+
return try modifyPair(pair,
|
|
83
|
+
from: from,
|
|
84
|
+
destination: destination,
|
|
85
|
+
prefix: prefix)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return modifiedPairs.joined(separator: " AND ")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// MARK: - getColumnValuePairs
|
|
92
|
+
|
|
93
|
+
class func getColumnValuePairs(from: [String],
|
|
94
|
+
destination: [String],
|
|
95
|
+
whereClause: String) -> [String] {
|
|
96
|
+
if whereClause.contains("AND") {
|
|
97
|
+
if #available(iOS 16.0, *) {
|
|
98
|
+
return whereClause.split(separator: "AND").map({ String($0) })
|
|
99
|
+
} else {
|
|
100
|
+
return whereClause.components(separatedBy: "AND")
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
return [whereClause]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class func modifyPair(_ pair: String, from: [String],
|
|
107
|
+
destination: [String],prefix: String) throws -> String {
|
|
108
|
+
|
|
109
|
+
let pattern = #"(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)"#
|
|
110
|
+
|
|
111
|
+
guard let range = pair.range(of: pattern, options: .regularExpression) else {
|
|
112
|
+
return pair
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let match = String(pair[range])
|
|
116
|
+
let regex = try NSRegularExpression(pattern: pattern)
|
|
117
|
+
let matchRange = NSRange(match.startIndex..., in: match)
|
|
118
|
+
|
|
119
|
+
guard let matchResult = regex.firstMatch(in: match, range: matchRange) else {
|
|
120
|
+
let msg = "addPrefixToWhereClause: match result not found"
|
|
121
|
+
throw UtilsSQLStatementError.addPrefixToWhereClause(message: msg)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
guard let columnRange = Range(matchResult.range(at: 1), in: match) else {
|
|
125
|
+
let msg = "addPrefixToWhereClause: columnRange failed"
|
|
126
|
+
throw UtilsSQLStatementError.addPrefixToWhereClause(message: msg)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
guard let operatorRange = Range(matchResult.range(at: 2), in: match) else {
|
|
130
|
+
let msg = "addPrefixToWhereClause: " +
|
|
131
|
+
"operatorRange failed "
|
|
132
|
+
throw UtilsSQLStatementError
|
|
133
|
+
.addPrefixToWhereClause(message: msg)
|
|
134
|
+
}
|
|
135
|
+
guard let valueRange = Range(matchResult.range(at: 3), in: match) else {
|
|
136
|
+
let msg = "addPrefixToWhereClause: " +
|
|
137
|
+
"valueRange failed "
|
|
138
|
+
throw UtilsSQLStatementError
|
|
139
|
+
.addPrefixToWhereClause(message: msg)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let column = String(match[columnRange]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
143
|
+
let mOperator = String(match[operatorRange]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
144
|
+
let value = String(match[valueRange]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
145
|
+
|
|
146
|
+
var newColumn = column
|
|
147
|
+
if let index = UtilsSQLStatement
|
|
148
|
+
.findIndexOfStringInArray(column, destination), index != -1 {
|
|
149
|
+
guard let mNewColumn = UtilsSQLStatement
|
|
150
|
+
.getStringAtIndex(from, index) else {
|
|
151
|
+
let msg = "addPrefixToWhereClause: index " +
|
|
152
|
+
"mistmatch "
|
|
153
|
+
throw UtilsSQLStatementError
|
|
154
|
+
.addPrefixToWhereClause(message: msg)
|
|
155
|
+
}
|
|
156
|
+
newColumn = mNewColumn
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let modifiedColumn = "\(prefix)\(newColumn)"
|
|
160
|
+
return "\(modifiedColumn) \(mOperator) \(value)"
|
|
161
|
+
}
|
|
162
|
+
/*
|
|
163
|
+
class func addPrefixToWhereClause(_ whereClause: String,
|
|
164
|
+
from: [String],
|
|
165
|
+
destination: [String], prefix: String)
|
|
73
166
|
throws -> String {
|
|
74
167
|
var columnValuePairs: [String]
|
|
75
168
|
if whereClause.contains("AND") {
|
|
76
169
|
if #available(iOS 16.0, *) {
|
|
77
170
|
let subSequenceArray = whereClause.split(separator: "AND")
|
|
78
|
-
columnValuePairs = subSequenceArray.map
|
|
171
|
+
columnValuePairs = subSequenceArray.map({ String($0) })
|
|
79
172
|
} else {
|
|
80
173
|
columnValuePairs = whereClause
|
|
81
174
|
.components(separatedBy: "AND")
|
|
@@ -83,7 +176,7 @@ class UtilsSQLStatement {
|
|
|
83
176
|
} else {
|
|
84
177
|
columnValuePairs = [whereClause]
|
|
85
178
|
}
|
|
86
|
-
let modifiedPairs = try columnValuePairs.map
|
|
179
|
+
let modifiedPairs = try columnValuePairs.map({ pair -> String in
|
|
87
180
|
let pattern = #"(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)"#
|
|
88
181
|
|
|
89
182
|
if let range = pair.range(of: pattern, options: .regularExpression) {
|
|
@@ -92,9 +185,25 @@ class UtilsSQLStatement {
|
|
|
92
185
|
let matchRange = NSRange(match.startIndex..., in: match)
|
|
93
186
|
|
|
94
187
|
if let matchResult = regex.firstMatch(in: match, range: matchRange) {
|
|
95
|
-
|
|
96
|
-
let
|
|
97
|
-
|
|
188
|
+
|
|
189
|
+
guard let columnRange = Range(matchResult.range(at: 1), in: match) else {
|
|
190
|
+
let msg = "addPrefixToWhereClause: " +
|
|
191
|
+
"columnRange failed "
|
|
192
|
+
throw UtilsSQLStatementError
|
|
193
|
+
.addPrefixToWhereClause(message: msg)
|
|
194
|
+
}
|
|
195
|
+
guard let operatorRange = Range(matchResult.range(at: 2), in: match) else {
|
|
196
|
+
let msg = "addPrefixToWhereClause: " +
|
|
197
|
+
"operatorRange failed "
|
|
198
|
+
throw UtilsSQLStatementError
|
|
199
|
+
.addPrefixToWhereClause(message: msg)
|
|
200
|
+
}
|
|
201
|
+
guard let valueRange = Range(matchResult.range(at: 3), in: match) else {
|
|
202
|
+
let msg = "addPrefixToWhereClause: " +
|
|
203
|
+
"valueRange failed "
|
|
204
|
+
throw UtilsSQLStatementError
|
|
205
|
+
.addPrefixToWhereClause(message: msg)
|
|
206
|
+
}
|
|
98
207
|
|
|
99
208
|
let column = String(match[columnRange]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
100
209
|
let mOperator = String(match[operatorRange]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
@@ -102,7 +211,7 @@ class UtilsSQLStatement {
|
|
|
102
211
|
|
|
103
212
|
var newColumn = column
|
|
104
213
|
if let index = UtilsSQLStatement
|
|
105
|
-
.findIndexOfStringInArray(column,
|
|
214
|
+
.findIndexOfStringInArray(column, destination), index != -1 {
|
|
106
215
|
guard let mNewColumn = UtilsSQLStatement
|
|
107
216
|
.getStringAtIndex(from, index) else {
|
|
108
217
|
let msg = "addPrefixToWhereClause: index " +
|
|
@@ -118,11 +227,11 @@ class UtilsSQLStatement {
|
|
|
118
227
|
}
|
|
119
228
|
}
|
|
120
229
|
return pair
|
|
121
|
-
}
|
|
230
|
+
})
|
|
122
231
|
return modifiedPairs.joined(separator: " AND ")
|
|
123
232
|
|
|
124
233
|
}
|
|
125
|
-
|
|
234
|
+
*/
|
|
126
235
|
// MARK: - findIndexOfStringInArray
|
|
127
236
|
|
|
128
237
|
class func findIndexOfStringInArray(_ target: String, _ array: [String]) -> Int? {
|
|
@@ -140,16 +249,18 @@ class UtilsSQLStatement {
|
|
|
140
249
|
}
|
|
141
250
|
// MARK: - extractForeignKeyInfo
|
|
142
251
|
|
|
143
|
-
// swiftlint:
|
|
144
|
-
// swiftlint:enable type_body_length
|
|
252
|
+
// swiftlint:disable function_body_length
|
|
145
253
|
class func extractForeignKeyInfo(from sqlStatement: String)
|
|
146
254
|
throws ->
|
|
147
255
|
[String: Any] {
|
|
148
256
|
var foreignKeyInfo: [String: Any] = [:]
|
|
149
257
|
// Define the regular expression patterns for extracting the
|
|
150
258
|
// FOREIGN KEY clause and composite primary keys
|
|
151
|
-
let foreignKeyPattern = #"
|
|
152
|
-
|
|
259
|
+
let foreignKeyPattern = #"""
|
|
260
|
+
\bFOREIGN\s+KEY\s*\(([^)]+)\)\s+
|
|
261
|
+
REFERENCES\s+(\w+)\s*\(([^)]+)\)\s+
|
|
262
|
+
(ON\s+DELETE\s+(RESTRICT|CASCADE|SET\s+NULL|SET\s+DEFAULT|NO\s+ACTION))?
|
|
263
|
+
"""#
|
|
153
264
|
// Create a regular expression object
|
|
154
265
|
guard let regex = try? NSRegularExpression(
|
|
155
266
|
pattern: foreignKeyPattern, options: []) else {
|
|
@@ -224,7 +335,7 @@ class UtilsSQLStatement {
|
|
|
224
335
|
foreignKeyInfo["action"] = "NO_ACTION"
|
|
225
336
|
return foreignKeyInfo
|
|
226
337
|
}
|
|
227
|
-
// swiftlint:enable
|
|
338
|
+
// swiftlint:enable function_body_length
|
|
228
339
|
|
|
229
340
|
// MARK: - extractColumnNames
|
|
230
341
|
|
|
@@ -265,7 +376,7 @@ class UtilsSQLStatement {
|
|
|
265
376
|
}
|
|
266
377
|
}
|
|
267
378
|
|
|
268
|
-
func processToken(_ token: String) {
|
|
379
|
+
/* func processToken(_ token: String) {
|
|
269
380
|
if token.uppercased() == "IN" {
|
|
270
381
|
inClause = true
|
|
271
382
|
} else if inClause && (token.prefix(7).uppercased() == "(VALUES" ||
|
|
@@ -306,6 +417,82 @@ class UtilsSQLStatement {
|
|
|
306
417
|
inLike = false
|
|
307
418
|
}
|
|
308
419
|
}
|
|
420
|
+
*/
|
|
421
|
+
// swiftlint:disable cyclomatic_complexity
|
|
422
|
+
func processToken(_ token: String) {
|
|
423
|
+
if token.uppercased() == "IN" {
|
|
424
|
+
processIn(token)
|
|
425
|
+
} else if inClause && (token.prefix(7).uppercased() == "(VALUES" ||
|
|
426
|
+
token.prefix(8).uppercased() == "( VALUES") {
|
|
427
|
+
processInValues(token)
|
|
428
|
+
} else if inValues && (token.suffix(2).uppercased() == "))" ||
|
|
429
|
+
token.suffix(3).uppercased() == ") )") {
|
|
430
|
+
processEndInValues(token)
|
|
431
|
+
} else if inClause && !inValues && token.prefix(1) == "(" {
|
|
432
|
+
inPar = true
|
|
433
|
+
} else if inClause && !inValues && token.suffix(1) == ")" {
|
|
434
|
+
processEndInClause()
|
|
435
|
+
} else if token.uppercased() == "BETWEEN" {
|
|
436
|
+
betweenClause = true
|
|
437
|
+
} else if betweenClause && token.uppercased() == "AND" {
|
|
438
|
+
andClause = true
|
|
439
|
+
} else if operators.contains(token) {
|
|
440
|
+
inOper = true
|
|
441
|
+
} else if token.uppercased() == "LIKE" {
|
|
442
|
+
inLike = true
|
|
443
|
+
} else if shouldProcessColumn(token) {
|
|
444
|
+
processColumn(token)
|
|
445
|
+
} else if betweenClause && andClause {
|
|
446
|
+
processEndBetweenAnd()
|
|
447
|
+
} else if inOper {
|
|
448
|
+
processEndInOper()
|
|
449
|
+
} else if inLike {
|
|
450
|
+
processEndInLike()
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
// swiftlint:enable cyclomatic_complexity
|
|
454
|
+
|
|
455
|
+
func processIn(_ token: String) {
|
|
456
|
+
inClause = true
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
func processInValues(_ token: String) {
|
|
460
|
+
inValues = true
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
func processEndInValues(_ token: String) {
|
|
464
|
+
inValues = false
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
func processEndInClause() {
|
|
468
|
+
inPar = false
|
|
469
|
+
inClause = false
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
func shouldProcessColumn(_ token: String) -> Bool {
|
|
473
|
+
token.range(of: "\\b[a-zA-Z]\\w*\\b", options: .regularExpression) != nil
|
|
474
|
+
&& !inClause && (!inValues || !inPar)
|
|
475
|
+
&& !betweenClause && !andClause && !inOper && !inLike
|
|
476
|
+
&& !keywords.contains(token.uppercased())
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
func processColumn(_ token: String) {
|
|
480
|
+
var mToken = extractString(from: token)
|
|
481
|
+
mToken = removeOperatorsAndFollowing(from: mToken)
|
|
482
|
+
columns.append(mToken)
|
|
483
|
+
}
|
|
484
|
+
func processEndBetweenAnd() {
|
|
485
|
+
betweenClause = false
|
|
486
|
+
andClause = false
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
func processEndInOper() {
|
|
490
|
+
inOper = false
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
func processEndInLike() {
|
|
494
|
+
inLike = false
|
|
495
|
+
}
|
|
309
496
|
let tokens = whereClause.components(separatedBy: CharacterSet(charactersIn: " ,"))
|
|
310
497
|
for token in tokens {
|
|
311
498
|
processToken(token)
|
|
@@ -324,84 +511,91 @@ class UtilsSQLStatement {
|
|
|
324
511
|
|
|
325
512
|
// MARK: - isReturning
|
|
326
513
|
|
|
327
|
-
class func isReturning(sqlStmt: String) ->
|
|
328
|
-
let stmtType = sqlStmt
|
|
329
|
-
|
|
330
|
-
.components(separatedBy: " ")
|
|
331
|
-
.first?.capitalized ?? ""
|
|
332
|
-
var stmt = sqlStmt.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
333
|
-
if stmt.hasSuffix(";") {
|
|
334
|
-
// Remove the suffix
|
|
335
|
-
stmt = String(stmt.dropLast())
|
|
336
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
337
|
-
}
|
|
338
|
-
|
|
514
|
+
class func isReturning(sqlStmt: String) -> SQLStatementInfo {
|
|
515
|
+
let stmtType = getStatementType(sqlStmt)
|
|
516
|
+
let stmt = cleanStatement(sqlStmt)
|
|
339
517
|
switch stmtType {
|
|
340
|
-
|
|
341
518
|
case "INSERT":
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
var resultString = String(substringAfterValues)
|
|
354
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
355
|
-
if resultString.count > 0 && !resultString.hasSuffix(";") {
|
|
356
|
-
resultString += ";"
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
let substringStartToEndParenthesis = stmt[...closingParenthesisIndex]
|
|
360
|
-
let stmtString = String(substringStartToEndParenthesis)
|
|
361
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
362
|
-
.appending(";")
|
|
519
|
+
return processInsertStatement(sqlStmt, stmt: stmt)
|
|
520
|
+
case "DELETE", "UPDATE":
|
|
521
|
+
return processDeleteOrUpdateStatement(sqlStmt, stmt: stmt)
|
|
522
|
+
default:
|
|
523
|
+
return SQLStatementInfo(isReturning: false, stmtString: sqlStmt, resultString: "")
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
class func getStatementType(_ sqlStmt: String) -> String {
|
|
527
|
+
let trimmedStmt = sqlStmt.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
528
|
+
return trimmedStmt.components(separatedBy: " ").first?.uppercased() ?? ""
|
|
529
|
+
}
|
|
363
530
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
531
|
+
class func cleanStatement(_ sqlStmt: String) -> String {
|
|
532
|
+
var cleanedStmt = sqlStmt.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
533
|
+
if cleanedStmt.hasSuffix(";") {
|
|
534
|
+
cleanedStmt = String(cleanedStmt.dropLast())
|
|
535
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
536
|
+
}
|
|
537
|
+
return cleanedStmt
|
|
538
|
+
}
|
|
539
|
+
class func processInsertStatement(_ sqlStmt: String, stmt: String) -> SQLStatementInfo {
|
|
540
|
+
if let valuesIndex = stmt.range(of: "VALUES", options: .caseInsensitive)?.lowerBound,
|
|
541
|
+
let closingParenthesisIndex = stmt
|
|
542
|
+
.range(of: ")", options: .backwards, range: valuesIndex..<stmt.endIndex)?
|
|
543
|
+
.upperBound {
|
|
544
|
+
var mStmt = stmt
|
|
545
|
+
guard closingParenthesisIndex < mStmt.endIndex else {
|
|
546
|
+
mStmt += ";"
|
|
547
|
+
return SQLStatementInfo(isReturning: false, stmtString: mStmt, resultString: "")
|
|
369
548
|
}
|
|
370
|
-
return (false, sqlStmt, "")
|
|
371
549
|
|
|
372
|
-
|
|
373
|
-
let
|
|
374
|
-
var
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
for word in words {
|
|
379
|
-
if word.lowercased() == "returning" {
|
|
380
|
-
isReturningOutsideMessage = true
|
|
381
|
-
// Include "RETURNING" and the words after it in returningString
|
|
382
|
-
returningString.append(contentsOf: [word] + UtilsSQLStatement.wordsAfter(word, in: words))
|
|
383
|
-
break
|
|
384
|
-
}
|
|
385
|
-
wordsBeforeReturning.append(word)
|
|
550
|
+
let intParenthesisValue = mStmt.distance(from: mStmt.startIndex, to: closingParenthesisIndex)
|
|
551
|
+
let substringAfterValues = stmt[closingParenthesisIndex...]
|
|
552
|
+
var resultString = String(substringAfterValues)
|
|
553
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
554
|
+
if resultString.count > 0 && !resultString.hasSuffix(";") {
|
|
555
|
+
resultString += ";"
|
|
386
556
|
}
|
|
387
557
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
!joinedReturningString.hasSuffix(";") {
|
|
393
|
-
joinedReturningString += ";"
|
|
394
|
-
}
|
|
558
|
+
let substringStartToEndParenthesis = mStmt[...closingParenthesisIndex]
|
|
559
|
+
let stmtString = String(substringStartToEndParenthesis)
|
|
560
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
561
|
+
.appending(";")
|
|
395
562
|
|
|
396
|
-
|
|
563
|
+
if substringAfterValues.lowercased().contains("returning") {
|
|
564
|
+
return SQLStatementInfo(isReturning: true, stmtString: stmtString, resultString: resultString)
|
|
397
565
|
} else {
|
|
398
|
-
return (false, sqlStmt, "")
|
|
566
|
+
return SQLStatementInfo(isReturning: false, stmtString: sqlStmt, resultString: "")
|
|
399
567
|
}
|
|
568
|
+
}
|
|
569
|
+
return SQLStatementInfo(isReturning: false, stmtString: sqlStmt, resultString: "")
|
|
570
|
+
}
|
|
400
571
|
|
|
401
|
-
|
|
402
|
-
|
|
572
|
+
class func processDeleteOrUpdateStatement(_ sqlStmt: String, stmt: String) -> SQLStatementInfo {
|
|
573
|
+
let words = stmt.components(separatedBy: .whitespacesAndNewlines)
|
|
574
|
+
var wordsBeforeReturning: [String] = []
|
|
575
|
+
var returningString: [String] = []
|
|
576
|
+
|
|
577
|
+
var isReturningOutsideMessage = false
|
|
578
|
+
for word in words {
|
|
579
|
+
if word.lowercased() == "returning" {
|
|
580
|
+
isReturningOutsideMessage = true
|
|
581
|
+
// Include "RETURNING" and the words after it in returningString
|
|
582
|
+
returningString.append(contentsOf: [word] + UtilsSQLStatement.wordsAfter(word, in: words))
|
|
583
|
+
break
|
|
584
|
+
}
|
|
585
|
+
wordsBeforeReturning.append(word)
|
|
403
586
|
}
|
|
404
587
|
|
|
588
|
+
if isReturningOutsideMessage {
|
|
589
|
+
let joinedWords = wordsBeforeReturning.joined(separator: " ") + ";"
|
|
590
|
+
var joinedReturningString = returningString.joined(separator: " ")
|
|
591
|
+
if joinedReturningString.count > 0 &&
|
|
592
|
+
!joinedReturningString.hasSuffix(";") {
|
|
593
|
+
joinedReturningString += ";"
|
|
594
|
+
}
|
|
595
|
+
return SQLStatementInfo(isReturning: true, stmtString: joinedWords, resultString: joinedReturningString)
|
|
596
|
+
} else {
|
|
597
|
+
return SQLStatementInfo(isReturning: false, stmtString: sqlStmt, resultString: "")
|
|
598
|
+
}
|
|
405
599
|
}
|
|
406
600
|
|
|
407
601
|
// MARK: - wordsAfter
|
|
@@ -419,13 +613,13 @@ class UtilsSQLStatement {
|
|
|
419
613
|
-> [String: String] {
|
|
420
614
|
var retStmtNames: [String: String] = [:]
|
|
421
615
|
|
|
422
|
-
let
|
|
423
|
-
retStmtNames["stmt"] =
|
|
616
|
+
let statementInfo = isReturning(sqlStmt: sqlStmt)
|
|
617
|
+
retStmtNames["stmt"] = statementInfo.stmtString
|
|
424
618
|
retStmtNames["names"] = ""
|
|
425
|
-
if isReturning && retMode.prefix(2) == "wA" {
|
|
426
|
-
let lowercaseSuffix =
|
|
619
|
+
if statementInfo.isReturning && retMode.prefix(2) == "wA" {
|
|
620
|
+
let lowercaseSuffix = statementInfo.resultString.lowercased()
|
|
427
621
|
if let returningIndex = lowercaseSuffix.range(of: "returning") {
|
|
428
|
-
let substring =
|
|
622
|
+
let substring = statementInfo.resultString[returningIndex.upperBound...]
|
|
429
623
|
|
|
430
624
|
let names =
|
|
431
625
|
"\(substring)".trimmingLeadingAndTrailingSpaces()
|
|
@@ -436,7 +630,7 @@ class UtilsSQLStatement {
|
|
|
436
630
|
}
|
|
437
631
|
|
|
438
632
|
// MARK: - getNames
|
|
439
|
-
|
|
633
|
+
|
|
440
634
|
class func getNames(from input: String) -> String {
|
|
441
635
|
// Find the index of the first occurrence of ";", "--", or "/*"
|
|
442
636
|
let indexSemicolon = input.firstIndex(of: ";")
|
|
@@ -454,12 +648,12 @@ class UtilsSQLStatement {
|
|
|
454
648
|
if let index = indexCommentStart?.lowerBound {
|
|
455
649
|
minIndex = min(minIndex, index)
|
|
456
650
|
}
|
|
457
|
-
|
|
651
|
+
|
|
458
652
|
// Extract substring up to the minimum index
|
|
459
653
|
let colnames = String(input[..<minIndex]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
460
654
|
return colnames
|
|
461
655
|
}
|
|
462
|
-
|
|
656
|
+
|
|
463
657
|
// MARK: - extractCombinedPrimaryKey
|
|
464
658
|
|
|
465
659
|
class func extractCombinedPrimaryKey(from whereClause: String)
|
|
@@ -484,8 +678,8 @@ class UtilsSQLStatement {
|
|
|
484
678
|
|
|
485
679
|
if let keysRange = Range(match.range(at: 1), in: whereClause) {
|
|
486
680
|
let keysString = String(whereClause[keysRange])
|
|
487
|
-
let keys = keysString.split(separator: ",").map
|
|
488
|
-
String($0.trimmingCharacters(in: .whitespaces)) }
|
|
681
|
+
let keys = keysString.split(separator: ",").map({
|
|
682
|
+
String($0.trimmingCharacters(in: .whitespaces)) })
|
|
489
683
|
primaryKeySets.append(keys)
|
|
490
684
|
}
|
|
491
685
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.3-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",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@capacitor/android": "^5.7.
|
|
63
|
-
"@capacitor/cli": "^5.7.
|
|
64
|
-
"@capacitor/core": "^5.7.
|
|
62
|
+
"@capacitor/android": "^5.7.3",
|
|
63
|
+
"@capacitor/cli": "^5.7.3",
|
|
64
|
+
"@capacitor/core": "^5.7.3",
|
|
65
65
|
"@capacitor/docgen": "^0.0.17",
|
|
66
|
-
"@capacitor/ios": "^5.7.
|
|
66
|
+
"@capacitor/ios": "^5.7.3",
|
|
67
67
|
"@ionic/eslint-config": "^0.3.0",
|
|
68
68
|
"@ionic/prettier-config": "^1.0.1",
|
|
69
69
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"prettier-plugin-java": "~1.0.2",
|
|
75
75
|
"rimraf": "^3.0.2",
|
|
76
76
|
"rollup": "^2.32.0",
|
|
77
|
-
"swiftlint": "^1.0.
|
|
77
|
+
"swiftlint": "^1.0.2",
|
|
78
78
|
"typescript": "~4.1.5"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
@@ -97,6 +97,6 @@
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"jeep-sqlite": "^2.
|
|
100
|
+
"jeep-sqlite": "^2.7.0"
|
|
101
101
|
}
|
|
102
102
|
}
|