@capacitor-community/sqlite 5.7.1 → 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/dist/esm/web.js +21 -22
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +21 -22
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +21 -22
- package/dist/plugin.js.map +1 -1
- 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 +285 -92
- package/package.json +7 -7
- package/src/web.ts +1 -2
|
@@ -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,8 +335,7 @@ class UtilsSQLStatement {
|
|
|
224
335
|
foreignKeyInfo["action"] = "NO_ACTION"
|
|
225
336
|
return foreignKeyInfo
|
|
226
337
|
}
|
|
227
|
-
// swiftlint:enable
|
|
228
|
-
// swiftlint:disable function_body_length
|
|
338
|
+
// swiftlint:enable function_body_length
|
|
229
339
|
|
|
230
340
|
// MARK: - extractColumnNames
|
|
231
341
|
|
|
@@ -266,7 +376,7 @@ class UtilsSQLStatement {
|
|
|
266
376
|
}
|
|
267
377
|
}
|
|
268
378
|
|
|
269
|
-
func processToken(_ token: String) {
|
|
379
|
+
/* func processToken(_ token: String) {
|
|
270
380
|
if token.uppercased() == "IN" {
|
|
271
381
|
inClause = true
|
|
272
382
|
} else if inClause && (token.prefix(7).uppercased() == "(VALUES" ||
|
|
@@ -307,6 +417,82 @@ class UtilsSQLStatement {
|
|
|
307
417
|
inLike = false
|
|
308
418
|
}
|
|
309
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
|
+
}
|
|
310
496
|
let tokens = whereClause.components(separatedBy: CharacterSet(charactersIn: " ,"))
|
|
311
497
|
for token in tokens {
|
|
312
498
|
processToken(token)
|
|
@@ -325,84 +511,91 @@ class UtilsSQLStatement {
|
|
|
325
511
|
|
|
326
512
|
// MARK: - isReturning
|
|
327
513
|
|
|
328
|
-
class func isReturning(sqlStmt: String) ->
|
|
329
|
-
let stmtType = sqlStmt
|
|
330
|
-
|
|
331
|
-
.components(separatedBy: " ")
|
|
332
|
-
.first?.capitalized ?? ""
|
|
333
|
-
var stmt = sqlStmt.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
334
|
-
if stmt.hasSuffix(";") {
|
|
335
|
-
// Remove the suffix
|
|
336
|
-
stmt = String(stmt.dropLast())
|
|
337
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
338
|
-
}
|
|
339
|
-
|
|
514
|
+
class func isReturning(sqlStmt: String) -> SQLStatementInfo {
|
|
515
|
+
let stmtType = getStatementType(sqlStmt)
|
|
516
|
+
let stmt = cleanStatement(sqlStmt)
|
|
340
517
|
switch stmtType {
|
|
341
|
-
|
|
342
518
|
case "INSERT":
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
var resultString = String(substringAfterValues)
|
|
355
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
356
|
-
if resultString.count > 0 && !resultString.hasSuffix(";") {
|
|
357
|
-
resultString += ";"
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
let substringStartToEndParenthesis = stmt[...closingParenthesisIndex]
|
|
361
|
-
let stmtString = String(substringStartToEndParenthesis)
|
|
362
|
-
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
363
|
-
.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
|
+
}
|
|
364
530
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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: "")
|
|
370
548
|
}
|
|
371
|
-
return (false, sqlStmt, "")
|
|
372
549
|
|
|
373
|
-
|
|
374
|
-
let
|
|
375
|
-
var
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
for word in words {
|
|
380
|
-
if word.lowercased() == "returning" {
|
|
381
|
-
isReturningOutsideMessage = true
|
|
382
|
-
// Include "RETURNING" and the words after it in returningString
|
|
383
|
-
returningString.append(contentsOf: [word] + UtilsSQLStatement.wordsAfter(word, in: words))
|
|
384
|
-
break
|
|
385
|
-
}
|
|
386
|
-
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 += ";"
|
|
387
556
|
}
|
|
388
557
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
!joinedReturningString.hasSuffix(";") {
|
|
394
|
-
joinedReturningString += ";"
|
|
395
|
-
}
|
|
558
|
+
let substringStartToEndParenthesis = mStmt[...closingParenthesisIndex]
|
|
559
|
+
let stmtString = String(substringStartToEndParenthesis)
|
|
560
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
561
|
+
.appending(";")
|
|
396
562
|
|
|
397
|
-
|
|
563
|
+
if substringAfterValues.lowercased().contains("returning") {
|
|
564
|
+
return SQLStatementInfo(isReturning: true, stmtString: stmtString, resultString: resultString)
|
|
398
565
|
} else {
|
|
399
|
-
return (false, sqlStmt, "")
|
|
566
|
+
return SQLStatementInfo(isReturning: false, stmtString: sqlStmt, resultString: "")
|
|
400
567
|
}
|
|
568
|
+
}
|
|
569
|
+
return SQLStatementInfo(isReturning: false, stmtString: sqlStmt, resultString: "")
|
|
570
|
+
}
|
|
401
571
|
|
|
402
|
-
|
|
403
|
-
|
|
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)
|
|
404
586
|
}
|
|
405
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
|
+
}
|
|
406
599
|
}
|
|
407
600
|
|
|
408
601
|
// MARK: - wordsAfter
|
|
@@ -420,13 +613,13 @@ class UtilsSQLStatement {
|
|
|
420
613
|
-> [String: String] {
|
|
421
614
|
var retStmtNames: [String: String] = [:]
|
|
422
615
|
|
|
423
|
-
let
|
|
424
|
-
retStmtNames["stmt"] =
|
|
616
|
+
let statementInfo = isReturning(sqlStmt: sqlStmt)
|
|
617
|
+
retStmtNames["stmt"] = statementInfo.stmtString
|
|
425
618
|
retStmtNames["names"] = ""
|
|
426
|
-
if isReturning && retMode.prefix(2) == "wA" {
|
|
427
|
-
let lowercaseSuffix =
|
|
619
|
+
if statementInfo.isReturning && retMode.prefix(2) == "wA" {
|
|
620
|
+
let lowercaseSuffix = statementInfo.resultString.lowercased()
|
|
428
621
|
if let returningIndex = lowercaseSuffix.range(of: "returning") {
|
|
429
|
-
let substring =
|
|
622
|
+
let substring = statementInfo.resultString[returningIndex.upperBound...]
|
|
430
623
|
|
|
431
624
|
let names =
|
|
432
625
|
"\(substring)".trimmingLeadingAndTrailingSpaces()
|
|
@@ -437,13 +630,13 @@ class UtilsSQLStatement {
|
|
|
437
630
|
}
|
|
438
631
|
|
|
439
632
|
// MARK: - getNames
|
|
440
|
-
|
|
633
|
+
|
|
441
634
|
class func getNames(from input: String) -> String {
|
|
442
635
|
// Find the index of the first occurrence of ";", "--", or "/*"
|
|
443
636
|
let indexSemicolon = input.firstIndex(of: ";")
|
|
444
637
|
let indexDoubleDash = input.range(of: "--")
|
|
445
638
|
let indexCommentStart = input.range(of: "/*")
|
|
446
|
-
|
|
639
|
+
|
|
447
640
|
// Find the minimum index among them
|
|
448
641
|
var minIndex = input.endIndex
|
|
449
642
|
if let index = indexSemicolon {
|
|
@@ -455,12 +648,12 @@ class UtilsSQLStatement {
|
|
|
455
648
|
if let index = indexCommentStart?.lowerBound {
|
|
456
649
|
minIndex = min(minIndex, index)
|
|
457
650
|
}
|
|
458
|
-
|
|
651
|
+
|
|
459
652
|
// Extract substring up to the minimum index
|
|
460
653
|
let colnames = String(input[..<minIndex]).trimmingCharacters(in: .whitespacesAndNewlines)
|
|
461
654
|
return colnames
|
|
462
655
|
}
|
|
463
|
-
|
|
656
|
+
|
|
464
657
|
// MARK: - extractCombinedPrimaryKey
|
|
465
658
|
|
|
466
659
|
class func extractCombinedPrimaryKey(from whereClause: String)
|
|
@@ -485,8 +678,8 @@ class UtilsSQLStatement {
|
|
|
485
678
|
|
|
486
679
|
if let keysRange = Range(match.range(at: 1), in: whereClause) {
|
|
487
680
|
let keysString = String(whereClause[keysRange])
|
|
488
|
-
let keys = keysString.split(separator: ",").map
|
|
489
|
-
String($0.trimmingCharacters(in: .whitespaces)) }
|
|
681
|
+
let keys = keysString.split(separator: ",").map({
|
|
682
|
+
String($0.trimmingCharacters(in: .whitespaces)) })
|
|
490
683
|
primaryKeySets.append(keys)
|
|
491
684
|
}
|
|
492
685
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "5.7.1",
|
|
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
|
}
|
package/src/web.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class CapacitorSQLiteWeb
|
|
|
45
45
|
private isWebStoreOpen = false;
|
|
46
46
|
|
|
47
47
|
async initWebStore(): Promise<void> {
|
|
48
|
-
|
|
48
|
+
await customElements.whenDefined('jeep-sqlite')
|
|
49
49
|
|
|
50
50
|
this.jeepSqliteElement = document.querySelector('jeep-sqlite');
|
|
51
51
|
this.ensureJeepSqliteIsAvailable();
|
|
@@ -86,7 +86,6 @@ export class CapacitorSQLiteWeb
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
return;
|
|
89
|
-
});
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
async saveToStore(options: capSQLiteOptions): Promise<void> {
|