aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/providers/contacts/util/DbQueryUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/contacts/util/DbQueryUtils.java')
-rw-r--r--src/com/android/providers/contacts/util/DbQueryUtils.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/com/android/providers/contacts/util/DbQueryUtils.java b/src/com/android/providers/contacts/util/DbQueryUtils.java
index c853a961..c184613f 100644
--- a/src/com/android/providers/contacts/util/DbQueryUtils.java
+++ b/src/com/android/providers/contacts/util/DbQueryUtils.java
@@ -94,4 +94,31 @@ public class DbQueryUtils {
}
}
}
+
+ /**
+ * Escape values to be used in LIKE sqlite clause.
+ *
+ * The LIKE clause has two special characters: '%' and '_'. If either of these
+ * characters need to be matched literally, then they must be escaped like so:
+ *
+ * WHERE value LIKE 'android\_%' ESCAPE '\'
+ *
+ * The ESCAPE clause is required and no default exists as the escape character in this context.
+ * Since the escape character needs to be defined as part of the sql string, it must be
+ * provided to this method so the escape characters match.
+ *
+ * @param sb The StringBuilder to append the escaped value to.
+ * @param value The value to be escaped.
+ * @param escapeChar The escape character to be defined in the sql ESCAPE clause.
+ */
+ public static void escapeLikeValue(StringBuilder sb, String value, char escapeChar) {
+ for (int i = 0; i < value.length(); i++) {
+ char ch = value.charAt(i);
+ if (ch == '%' || ch == '_') {
+ sb.append(escapeChar);
+ }
+ sb.append(ch);
+ }
+ }
+
}