Skip to content

Commit 1dac630

Browse files
committed
Fix Android V6 issue#562
1 parent aca3073 commit 1dac630

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 6.0.0-beta.2 (2024-06-12)
2+
3+
### Bug Fixes
4+
5+
- Fix Android Multi Row Statement does not suppress control characters ($) issue#562
6+
17
# 6.0.0-beta.1 (2024-06-12)
28

39
### Chore
0 Bytes
Binary file not shown.

android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,21 @@ public String replacePlaceholders(String stmt, String sqlBuilder) {
538538
if (extractedValues == null) {
539539
return stmt; // Return the original statement if no placeholders are found
540540
}
541+
// Regex to match the VALUES clause with varying number of placeholders
542+
String regex = "(?i)VALUES\\s*\\((\\s*\\?\\s*(?:,\\s*\\?\\s*)*)\\)";
541543

542-
// Replace placeholders in the stmt with values from sqlBuilder
543-
return stmt.replaceFirst("(?i)VALUES \\((\\?(?:,\\s*\\?\\s*)*)\\)", "VALUES " + sqlBuilder);
544+
// Create a pattern and matcher
545+
Pattern pattern = Pattern.compile(regex);
546+
Matcher matcher = pattern.matcher(stmt);
547+
548+
// Check if the pattern matches and perform the replacement
549+
if (matcher.find()) {
550+
// Perform the replacement without causing an IndexOutOfBoundsException
551+
String formattedStmt = matcher.replaceAll("VALUES " + Matcher.quoteReplacement(sqlBuilder));
552+
return formattedStmt;
553+
} else {
554+
throw new IllegalArgumentException("The statement does not contain a valid VALUES clause with placeholders.");
555+
}
544556
}
545557

546558
public String extractQuestionMarkValues(String input) {

0 commit comments

Comments
 (0)