From de51f37cd90bacfa17a2794708457c7a6b876bfb Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Fri, 26 Oct 2012 08:30:31 +0800 Subject: [PATCH] fixed sqlite query bug in Utils.isFiltered() --- src/org/mariotaku/twidere/util/Utils.java | 26 ++++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/org/mariotaku/twidere/util/Utils.java b/src/org/mariotaku/twidere/util/Utils.java index 7460f607..fdede926 100644 --- a/src/org/mariotaku/twidere/util/Utils.java +++ b/src/org/mariotaku/twidere/util/Utils.java @@ -670,9 +670,8 @@ public static int getAccountColor(final Context context, final long account_id) return Color.TRANSPARENT; } cur.moveToFirst(); - color = cur.getInt(cur.getColumnIndexOrThrow(Accounts.USER_COLOR)); + sAccountColors.put(account_id, color = cur.getInt(cur.getColumnIndexOrThrow(Accounts.USER_COLOR))); cur.close(); - sAccountColors.put(account_id, color); } return color; } @@ -1579,30 +1578,27 @@ public static boolean isFiltered(final SQLiteDatabase database, final String scr final String text_plain) { if (database == null) return false; final StringBuilder builder = new StringBuilder(); - builder.append("SELECT "); - builder.append("(SELECT '" + text_plain + "' LIKE '%'||" + TABLE_FILTERED_KEYWORDS + "." + Filters.TEXT + final String[] selection_args = new String[]{ text_plain, screen_name, source }; + builder.append("SELECT NULL WHERE"); + builder.append("(SELECT ? LIKE '%'||" + TABLE_FILTERED_KEYWORDS + "." + Filters.TEXT + "||'%' FROM " + TABLE_FILTERED_KEYWORDS + ")"); if (screen_name != null) { builder.append(" OR "); - builder.append("(SELECT '" + screen_name + "' IN (SELECT " + Filters.TEXT + " FROM " + TABLE_FILTERED_USERS + builder.append("(SELECT ? IN (SELECT " + Filters.TEXT + " FROM " + TABLE_FILTERED_USERS + "))"); } if (source != null) { builder.append(" OR "); - builder.append("(SELECT '" + source + "' LIKE '%>'||" + TABLE_FILTERED_SOURCES + "." + Filters.TEXT + builder.append("(SELECT ? LIKE '%>'||" + TABLE_FILTERED_SOURCES + "." + Filters.TEXT + "||'%' FROM " + TABLE_FILTERED_SOURCES + ")"); } - final Cursor cur = database.rawQuery(builder.toString(), null); + final Cursor cur = database.rawQuery(builder.toString(), selection_args); if (cur == null) return false; - if (cur.getCount() > 0) { - cur.moveToFirst(); - if (cur.getInt(0) == 1) { - cur.close(); - return true; - } + try { + return cur.getCount() > 0; + } finally { + cur.close(); } - cur.close(); - return false; } public static boolean isMyAccount(final Context context, final long account_id) {