diff options
author | Oguz Kocer <oguz.kocer@automattic.com> | 2016-08-02 16:18:06 +0300 |
---|---|---|
committer | Oguz Kocer <oguz.kocer@automattic.com> | 2016-08-02 16:18:06 +0300 |
commit | 093545d4eb1ed2e637016674439e7901ebeecd1d (patch) | |
tree | b9a18079be3be89e1b5ecbbe6540519889697c41 | |
parent | 5dd871f8406bfbf486dc52fe376ca724f90848d0 (diff) | |
download | gradle-perf-android-medium-093545d4eb1ed2e637016674439e7901ebeecd1d.tar.gz |
Fixes crash in PeopleTable due to malformed sql
We used to have "DESC" in our sql even if the query didn't have an "order by" component. The descending order component moved to the `orderByString` helper function.
-rw-r--r-- | WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java index 547272b01..6e89dba3f 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PeopleTable.java @@ -179,7 +179,7 @@ public class PeopleTable { int deleteCount = size - fetchLimit; String[] args = new String[] {Integer.toString(localTableBlogId), Integer.toString(deleteCount)}; getWritableDb().delete(table, "local_blog_id=?1 AND person_id IN (SELECT person_id FROM " - + table + " WHERE local_blog_id=?1" + orderByString(table) + " DESC LIMIT ?2)", args); + + table + " WHERE local_blog_id=?1" + orderByString(table, true) + " LIMIT ?2)", args); } } getWritableDb().setTransactionSuccessful(); @@ -232,7 +232,7 @@ public class PeopleTable { private static List<Person> getPeople(String table, int localTableBlogId) { String[] args = {Integer.toString(localTableBlogId)}; - String orderBy = orderByString(table); + String orderBy = orderByString(table, false); Cursor c = getReadableDb().rawQuery("SELECT * FROM " + table + " WHERE local_blog_id=?" + orderBy, args); List<Person> people = new ArrayList<>(); @@ -312,9 +312,9 @@ public class PeopleTable { } // order is disabled for followers & viewers for now since the API is not supporting it - private static String orderByString(String table) { + private static String orderByString(String table, boolean isDescending) { if (table.equals(TEAM_TABLE)) { - return " ORDER BY lower(display_name), lower(user_name)"; + return " ORDER BY lower(display_name), lower(user_name)" + (isDescending ? " DESC" : ""); } return ""; } |