@capacitor-community/sqlite 5.5.1-3 → 5.5.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/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +7 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +177 -64
- package/dist/esm/definitions.js +2 -9
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +2 -9
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -9
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +93 -21
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +8 -2
- package/ios/Plugin/Database.swift +2 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +3 -4
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +97 -11
- package/package.json +2 -2
- package/src/definitions.ts +3 -9
|
@@ -1547,7 +1547,10 @@ enum CapacitorSQLiteError: Error {
|
|
|
1547
1547
|
let aPath: String = try (UtilsFile.getFolderURL(folderPath: databaseLocation)).path
|
|
1548
1548
|
// get the database files
|
|
1549
1549
|
let dbList: [String] = try UtilsFile.getFileList(path: aPath, ext: ".db")
|
|
1550
|
-
|
|
1550
|
+
// filter for db including SQLite
|
|
1551
|
+
let dbWithSQLite = dbList.filter { $0.contains("SQLite") }
|
|
1552
|
+
|
|
1553
|
+
return dbWithSQLite
|
|
1551
1554
|
|
|
1552
1555
|
} catch let error {
|
|
1553
1556
|
let msg: String = "\(error)"
|
|
@@ -1564,7 +1567,10 @@ enum CapacitorSQLiteError: Error {
|
|
|
1564
1567
|
do {
|
|
1565
1568
|
let dbList: [String] = try UtilsMigrate
|
|
1566
1569
|
.getMigratableList(folderPath: folderPath)
|
|
1567
|
-
|
|
1570
|
+
// filter for db not including SQLite
|
|
1571
|
+
let dbNoSQLite = dbList.filter { !$0.contains("SQLite") }
|
|
1572
|
+
|
|
1573
|
+
return dbNoSQLite
|
|
1568
1574
|
|
|
1569
1575
|
} catch UtilsMigrateError.getMigratableList(let message) {
|
|
1570
1576
|
var msg: String = "getMigratableList:"
|
|
@@ -688,6 +688,8 @@ class Database {
|
|
|
688
688
|
if isExists {
|
|
689
689
|
// Set the last exported date
|
|
690
690
|
try ExportToJson.setLastExportDate(mDB: self, sTime: syncTime)
|
|
691
|
+
} else {
|
|
692
|
+
throw DatabaseError.exportToJson(message: "No sync_table available")
|
|
691
693
|
}
|
|
692
694
|
// Launch the export process
|
|
693
695
|
let data: [String: Any] = [
|
|
@@ -447,7 +447,7 @@ class UtilsSQLCipher {
|
|
|
447
447
|
msg.append("Database not opened")
|
|
448
448
|
throw UtilsSQLCipherError.prepareSQL(message: msg)
|
|
449
449
|
}
|
|
450
|
-
let systemVersion = UIDevice.current.systemVersion
|
|
450
|
+
// let systemVersion = UIDevice.current.systemVersion
|
|
451
451
|
var runSQLStatement: OpaquePointer?
|
|
452
452
|
var message: String = ""
|
|
453
453
|
var lastId: Int64 = -1
|
|
@@ -463,9 +463,7 @@ class UtilsSQLCipher {
|
|
|
463
463
|
retMode = "wA\(retMode)"
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
|
|
467
|
-
if (retMode == "no" || retMode.prefix(2) == "wA") &&
|
|
468
|
-
sqlStmt.uppercased().contains("RETURNING") {
|
|
466
|
+
if (retMode == "no" || retMode.prefix(2) == "wA")/* && isReturning*/ {
|
|
469
467
|
let stmtNames = UtilsSQLStatement
|
|
470
468
|
.getStmtAndRetColNames(sqlStmt: sqlStmt,
|
|
471
469
|
retMode: retMode)
|
|
@@ -556,6 +554,7 @@ class UtilsSQLCipher {
|
|
|
556
554
|
return (lastId, result)
|
|
557
555
|
}
|
|
558
556
|
}
|
|
557
|
+
|
|
559
558
|
|
|
560
559
|
// MARK: - returningWorkAround
|
|
561
560
|
|
|
@@ -323,28 +323,114 @@ class UtilsSQLStatement {
|
|
|
323
323
|
return lines.joined(separator: " ")
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
// MARK: - isReturning
|
|
327
|
+
|
|
328
|
+
class func isReturning(sqlStmt: String) -> (Bool, String, String) {
|
|
329
|
+
var stmt = sqlStmt.replacingOccurrences(of: "\n", with: "")
|
|
330
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
331
|
+
if stmt.hasSuffix(";") {
|
|
332
|
+
// Remove the suffix
|
|
333
|
+
stmt = String(stmt.dropLast())
|
|
334
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
switch (stmt.prefix(6).uppercased()) {
|
|
338
|
+
|
|
339
|
+
case "INSERT":
|
|
340
|
+
if let valuesIndex = stmt.range(of: "VALUES", options: .caseInsensitive)?.lowerBound,
|
|
341
|
+
let closingParenthesisIndex = stmt.range(of: ")", options: .backwards, range: valuesIndex..<stmt.endIndex)?.upperBound {
|
|
342
|
+
guard closingParenthesisIndex < stmt.endIndex else {
|
|
343
|
+
stmt += ";"
|
|
344
|
+
return (false, stmt, "")
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
let intParenthesisValue = stmt.distance(from: stmt.startIndex, to: closingParenthesisIndex)
|
|
348
|
+
let substringAfterValues = stmt[closingParenthesisIndex...]
|
|
349
|
+
var resultString = String(substringAfterValues)
|
|
350
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
351
|
+
if resultString.count > 0 && !resultString.hasSuffix(";") {
|
|
352
|
+
resultString += ";"
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let substringStartToEndParenthesis = stmt[...closingParenthesisIndex]
|
|
356
|
+
let stmtString = String(substringStartToEndParenthesis)
|
|
357
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
358
|
+
.appending(";")
|
|
359
|
+
|
|
360
|
+
if substringAfterValues.lowercased().contains("returning") {
|
|
361
|
+
return (true,stmtString,resultString)
|
|
362
|
+
} else {
|
|
363
|
+
return (false, stmt, "")
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return (false, stmt, "")
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
case "DELETE", "UPDATE":
|
|
370
|
+
let words = stmt.components(separatedBy: .whitespacesAndNewlines)
|
|
371
|
+
var wordsBeforeReturning: [String] = []
|
|
372
|
+
var returningString: [String] = []
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
var isReturningOutsideMessage = false
|
|
376
|
+
for word in words {
|
|
377
|
+
if word.lowercased() == "returning" {
|
|
378
|
+
isReturningOutsideMessage = true
|
|
379
|
+
// Include "RETURNING" and the words after it in returningString
|
|
380
|
+
returningString.append(contentsOf: [word] + UtilsSQLStatement.wordsAfter(word, in: words))
|
|
381
|
+
break
|
|
382
|
+
}
|
|
383
|
+
wordsBeforeReturning.append(word)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if isReturningOutsideMessage {
|
|
387
|
+
let joinedWords = wordsBeforeReturning.joined(separator: " ") + ";"
|
|
388
|
+
var joinedReturningString = returningString.joined(separator: " ")
|
|
389
|
+
if joinedReturningString.count > 0 &&
|
|
390
|
+
!joinedReturningString.hasSuffix(";") {
|
|
391
|
+
joinedReturningString += ";"
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return (true, joinedWords, joinedReturningString)
|
|
395
|
+
} else {
|
|
396
|
+
return (false, stmt, "")
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
default:
|
|
400
|
+
return (false, stmt, "")
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// MARK: - wordsAfter
|
|
406
|
+
|
|
407
|
+
class func wordsAfter(_ word: String, in words: [String]) -> [String] {
|
|
408
|
+
guard let index = words.firstIndex(of: word) else {
|
|
409
|
+
return []
|
|
410
|
+
}
|
|
411
|
+
return Array(words.suffix(from: index + 1))
|
|
412
|
+
}
|
|
413
|
+
|
|
326
414
|
// MARK: - getStmtAndRetColNames
|
|
327
415
|
|
|
328
416
|
class func getStmtAndRetColNames(sqlStmt: String, retMode: String)
|
|
329
417
|
-> [String: String] {
|
|
330
|
-
let retWord = "RETURNING"
|
|
331
|
-
|
|
332
418
|
var retStmtNames: [String: String] = [:]
|
|
333
|
-
|
|
419
|
+
|
|
420
|
+
let (isReturning, stmt, suffix) = isReturning(sqlStmt: sqlStmt)
|
|
421
|
+
retStmtNames["stmt"] = stmt
|
|
334
422
|
retStmtNames["names"] = ""
|
|
335
|
-
if
|
|
336
|
-
let
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
let suffix = sqlStmt.suffix(from: range.upperBound)
|
|
423
|
+
if isReturning && retMode.prefix(2) == "wA" {
|
|
424
|
+
let lowercaseSuffix = suffix.lowercased()
|
|
425
|
+
if let returningIndex = lowercaseSuffix.range(of: "returning") {
|
|
426
|
+
let substring = suffix[returningIndex.upperBound...]
|
|
427
|
+
|
|
341
428
|
let names =
|
|
342
|
-
|
|
429
|
+
"\(substring)".trimmingLeadingAndTrailingSpaces()
|
|
343
430
|
if names.suffix(1) == ";" {
|
|
344
431
|
retStmtNames["names"] = String(names.dropLast())
|
|
345
432
|
}
|
|
346
433
|
}
|
|
347
|
-
|
|
348
434
|
}
|
|
349
435
|
return retStmtNames
|
|
350
436
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor-community/sqlite",
|
|
3
|
-
"version": "5.5.1
|
|
3
|
+
"version": "5.5.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",
|
|
@@ -97,6 +97,6 @@
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"jeep-sqlite": "^2.5.
|
|
100
|
+
"jeep-sqlite": "^2.5.7"
|
|
101
101
|
}
|
|
102
102
|
}
|
package/src/definitions.ts
CHANGED
|
@@ -2207,30 +2207,24 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2207
2207
|
try {
|
|
2208
2208
|
if (!this.readonly) {
|
|
2209
2209
|
if (values && values.length > 0) {
|
|
2210
|
-
|
|
2211
|
-
? returnMode
|
|
2212
|
-
: 'no';
|
|
2210
|
+
|
|
2213
2211
|
res = await this.sqlite.run({
|
|
2214
2212
|
database: this.dbName,
|
|
2215
2213
|
statement: statement,
|
|
2216
2214
|
values: values,
|
|
2217
2215
|
transaction: transaction,
|
|
2218
2216
|
readonly: false,
|
|
2219
|
-
returnMode:
|
|
2217
|
+
returnMode: returnMode,
|
|
2220
2218
|
isSQL92: true,
|
|
2221
2219
|
});
|
|
2222
|
-
// }
|
|
2223
2220
|
} else {
|
|
2224
|
-
const mRetMode = statement.toUpperCase().includes('RETURNING')
|
|
2225
|
-
? returnMode
|
|
2226
|
-
: 'no';
|
|
2227
2221
|
res = await this.sqlite.run({
|
|
2228
2222
|
database: this.dbName,
|
|
2229
2223
|
statement: statement,
|
|
2230
2224
|
values: [],
|
|
2231
2225
|
transaction: transaction,
|
|
2232
2226
|
readonly: false,
|
|
2233
|
-
returnMode:
|
|
2227
|
+
returnMode: returnMode,
|
|
2234
2228
|
isSQL92: isSQL92,
|
|
2235
2229
|
});
|
|
2236
2230
|
}
|