Skip to content

Commit

Permalink
Fixed|Changed(SmsInboxAPI)!: Fix exception for message address/from s…
Browse files Browse the repository at this point in the history
…election and use exact match

SQL does not seem to consider `?` placeholders if inside quotes.

```
java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters.
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:472)
    at android.content.ContentResolver.query(ContentResolver.java:1183)
    at android.content.ContentResolver.query(ContentResolver.java:1115)
    at android.content.ContentResolver.query(ContentResolver.java:1071)
    at com.termux.api.apis.SmsInboxAPI.getAllSms(SmsInboxAPI.java:302)
```

Exact match is used by default so that only exactly matched entries are returned, users can use `%` wildcards in the address passed if they want to do prefix/contains/suffix matching.

- https://www.w3schools.com/sql/sql_like.asp
  • Loading branch information
agnostic-apollo committed Jan 25, 2025
1 parent 1b60b23 commit 12e7b65
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/api/apis/SmsInboxAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static void getAllSms(Context context, JsonWriter out,
String[] messageSelectionArgs = null;
if (messageSelection == null || messageSelection.isEmpty()) {
if (messageAddress != null && !messageAddress.isEmpty()) {
messageSelection = ADDRESS + " LIKE '%?%'";
messageSelection = ADDRESS + " LIKE ?";
messageSelectionArgs = new String[]{messageAddress};
}
}
Expand Down

0 comments on commit 12e7b65

Please sign in to comment.