mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-23 13:26:15 +03:00
Use ? instead of concat in NotesDatabase
This commit is contained in:
parent
0cb5398b68
commit
4a23044253
1 changed files with 31 additions and 17 deletions
|
@ -385,15 +385,19 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
||||||
String note_title = String.format("%s.%s", table_notes, key_category);
|
String note_title = String.format("%s.%s", table_notes, key_category);
|
||||||
String category_id = String.format("%s.%s", table_category, key_id);
|
String category_id = String.format("%s.%s", table_category, key_id);
|
||||||
String category_accountId = String.format("%s.%s", table_category, key_account_id);
|
String category_accountId = String.format("%s.%s", table_category, key_account_id);
|
||||||
|
String note_status = String.format("%s.%s", table_notes, key_status);
|
||||||
// Weird problem: If I use ? instead of concat directly, there is no result in the join table
|
// Weird problem: If I use ? instead of concat directly, there is no result in the join table
|
||||||
// TODO: Find a way to use ? instead of concat.
|
// TODO: Find a way to use ? instead of concat.
|
||||||
// TODO: a bug here
|
// TODO: a bug here
|
||||||
// when no notes and have cat, inner join will not return this cat
|
// when no notes and have cat, inner join will not return this cat
|
||||||
String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes +
|
String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category +
|
||||||
" ON " + category_id + " = " + note_title + " WHERE " + category_accountId + " = " + accountId +
|
" INNER JOIN " + table_notes + " ON " + category_id + " = " + note_title +
|
||||||
" GROUP BY " + category_id;
|
" WHERE " + category_accountId + " = ? AND " + note_status + " != ? GROUP BY " + category_id;
|
||||||
|
// String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes +
|
||||||
|
// " ON " + category_id + " = " + note_title + " WHERE " + category_accountId + " = " + accountId +
|
||||||
|
// " GROUP BY " + category_id;
|
||||||
|
|
||||||
Cursor cursor = getReadableDatabase().rawQuery(rawQuery, null);
|
Cursor cursor = getReadableDatabase().rawQuery(rawQuery, new String[]{String.valueOf(accountId), DBStatus.LOCAL_DELETED.getTitle()});
|
||||||
List<NavigationAdapter.NavigationItem> categories = new ArrayList<>(cursor.getCount());
|
List<NavigationAdapter.NavigationItem> categories = new ArrayList<>(cursor.getCount());
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
Resources res = getContext().getResources();
|
Resources res = getContext().getResources();
|
||||||
|
@ -422,23 +426,33 @@ public class NotesDatabase extends AbstractNotesDatabase {
|
||||||
String note_title = String.format("%s.%s", table_notes, key_category);
|
String note_title = String.format("%s.%s", table_notes, key_category);
|
||||||
String category_id = String.format("%s.%s", table_category, key_id);
|
String category_id = String.format("%s.%s", table_category, key_id);
|
||||||
String category_accountId = String.format("%s.%s", table_category, key_account_id);
|
String category_accountId = String.format("%s.%s", table_category, key_account_id);
|
||||||
// Weird problem: If I use ? instead of concat directly, there is no result in the join table
|
|
||||||
// TODO: Find a way to use ? instead of concat.
|
|
||||||
String rawQuery;
|
String rawQuery;
|
||||||
|
|
||||||
|
Cursor cursor;
|
||||||
if (search == null || search.trim().equals("")) {
|
if (search == null || search.trim().equals("")) {
|
||||||
rawQuery = String.format("SELECT %s, COUNT(*) FROM %s INNER JOIN %s ON %s = %s " +
|
rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes +
|
||||||
" WHERE %s != '%s' AND %s = %s AND %s != \"\" GROUP BY %s",
|
" ON " + note_title + " = " + category_id + " WHERE " + key_status + " != ? AND " + category_accountId +
|
||||||
category_title, table_category, table_notes, category_id, note_title,
|
" = ? AND " + category_title + " != \"\" GROUP BY " + category_id;
|
||||||
key_status, DBStatus.LOCAL_DELETED.getTitle(), category_accountId, String.valueOf(accountId),
|
|
||||||
category_title, category_id);
|
cursor = getReadableDatabase().rawQuery(rawQuery, new String[]{DBStatus.LOCAL_DELETED.getTitle(), String.valueOf(accountId)});
|
||||||
|
// rawQuery = String.format("SELECT %s, COUNT(*) FROM %s INNER JOIN %s ON %s = %s " +
|
||||||
|
// " WHERE %s != '%s' AND %s = %s AND %s != \"\" GROUP BY %s",
|
||||||
|
// category_title, table_category, table_notes, category_id, note_title,
|
||||||
|
// key_status, DBStatus.LOCAL_DELETED.getTitle(), category_accountId, String.valueOf(accountId),
|
||||||
|
// category_title, category_id);
|
||||||
} else {
|
} else {
|
||||||
rawQuery = String.format("SELECT %s, COUNT(*) FROM %s INNER JOIN %s ON %s = %s " +
|
rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes +
|
||||||
" WHERE %s != '%s' AND %s = %s AND %s LIKE %s AND %s != \"\" GROUP BY %s",
|
" ON " + note_title + " = " + category_id + " WHERE " + key_status + " != ? AND " + category_accountId +
|
||||||
category_title, table_category, table_notes, category_id, note_title,
|
" = ? AND " + category_title + " LIKE ? AND " + category_title + " != \"\" GROUP BY " + category_id;
|
||||||
key_status, DBStatus.LOCAL_DELETED.getTitle(), category_accountId, String.valueOf(accountId),
|
|
||||||
category_title, "'%" + search.trim() + "%'", category_title, category_id);
|
cursor = getReadableDatabase().rawQuery(rawQuery,
|
||||||
|
new String[]{DBStatus.LOCAL_DELETED.getTitle(), "'%" + search.trim() + "%'", String.valueOf(accountId)});
|
||||||
|
// rawQuery = String.format("SELECT %s, COUNT(*) FROM %s INNER JOIN %s ON %s = %s " +
|
||||||
|
// " WHERE %s != '%s' AND %s = %s AND %s LIKE %s AND %s != \"\" GROUP BY %s",
|
||||||
|
// category_title, table_category, table_notes, category_id, note_title,
|
||||||
|
// key_status, DBStatus.LOCAL_DELETED.getTitle(), category_accountId, String.valueOf(accountId),
|
||||||
|
// category_title, "'%" + search.trim() + "%'", category_title, category_id);
|
||||||
}
|
}
|
||||||
Cursor cursor = getReadableDatabase().rawQuery(rawQuery, null);
|
|
||||||
List<NavigationAdapter.NavigationItem> categories = new ArrayList<>(cursor.getCount());
|
List<NavigationAdapter.NavigationItem> categories = new ArrayList<>(cursor.getCount());
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
Resources res = getContext().getResources();
|
Resources res = getContext().getResources();
|
||||||
|
|
Loading…
Reference in a new issue