Fix " Cannot bind argument at index 1..." crash
Even when the specified account doesn't exist, we can't just replace
the entire selection with (1=2), because the orignal selection may have query
parameters. Let's just append "AND (1=2)" to the original query instead.
Bug 6295580
Change-Id: Ida13f17fe645329b1b1d5de76252abfb0fcbe282
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 13ec9b3..550639f 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -6975,15 +6975,20 @@
// already ruled out partial accounts.
final boolean validAccount = !TextUtils.isEmpty(accountWithDataSet.getAccountName());
if (validAccount) {
+ final StringBuilder selectionSb = new StringBuilder();
+
final Long accountId = mDbHelper.get().getAccountIdOrNull(accountWithDataSet);
if (accountId == null) {
// No such account in the accounts table. This means, there's no rows to be
// selected.
- return "(1=2)";
+ // Note even in this case, we still need to append the original selection, because
+ // it may have query parameters. If we remove these we'll get the # of parameters
+ // mismatch exception.
+ selectionSb.append("(1=2)");
+ } else {
+ selectionSb.append(RawContactsColumns.ACCOUNT_ID + "=");
+ selectionSb.append(Long.toString(accountId));
}
- final StringBuilder selectionSb = new StringBuilder(
- RawContactsColumns.ACCOUNT_ID + "=");
- selectionSb.append(Long.toString(accountId));
if (!TextUtils.isEmpty(selection)) {
selectionSb.append(" AND (");