Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 1540dca

Browse files
Sam1301kunall17
authored andcommitted
Fix: Use selectArgs in stream search db query.
1 parent 37c3804 commit 1540dca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,11 @@ public Cursor call() throws Exception {
672672
String query = "SELECT s.id as _id, s.name, s.color, count(case when m.id > " + pointer + " or m." + Message.MESSAGE_READ_FIELD
673673
+ " = 0 then 1 end) as " + ExpandableStreamDrawerAdapter.UNREAD_TABLE_NAME
674674
+ " FROM streams as s LEFT JOIN messages as m ON s.id=m.stream ";
675+
String selectArg = null;
675676
if (!etSearchStream.getText().toString().equals("") && !etSearchStream.getText().toString().isEmpty()) {
676677
//append where clause
677-
query += " WHERE s.name LIKE '%" + etSearchStream.getText().toString() + "%'" + " and s." + Stream.SUBSCRIBED_FIELD + " = " + "1 ";
678+
selectArg = etSearchStream.getText().toString() + '%';
679+
query += " WHERE s.name LIKE ? " + " and s." + Stream.SUBSCRIBED_FIELD + " = " + "1 ";
678680
//set visibility of this image false
679681
ivSearchStreamCancel.setVisibility(View.VISIBLE);
680682
} else {
@@ -685,7 +687,11 @@ public Cursor call() throws Exception {
685687
//append group by
686688
query += " group by s.name order by s.name COLLATE NOCASE";
687689

688-
return ((AndroidDatabaseResults) app.getDao(Stream.class).queryRaw(query).closeableIterator().getRawResults()).getRawCursor();
690+
if (selectArg != null) {
691+
return ((AndroidDatabaseResults) app.getDao(Stream.class).queryRaw(query, selectArg).closeableIterator().getRawResults()).getRawCursor();
692+
} else {
693+
return ((AndroidDatabaseResults) app.getDao(Stream.class).queryRaw(query).closeableIterator().getRawResults()).getRawCursor();
694+
}
689695
}
690696
};
691697
return steamCursorGenerator;

0 commit comments

Comments
 (0)