Skip to content

Commit

Permalink
Cast dblist as INTEGER to fix #525
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Sep 12, 2024
1 parent 33a7e77 commit f37d8f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s
result.setNotificationUri(getContext().getContentResolver(), uri);
break;
case Task.SECTIONEDDATEQUERYCODE:
// this branch runs when the user sorts notes by due date

// Add list null because that's what the headers will have
final String listId;
if (selectionArgs == null || selectionArgs.length == 0) {
Expand All @@ -450,10 +452,20 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s
} else {
listId = selectionArgs[0];
}

// Create view if not exists
DatabaseHandler.getInstance(getContext()).getWritableDatabase()
.execSQL(Task.CREATE_SECTIONED_DATE_VIEW(listId));
// TODO as explained in issue #525, on older OS versions (API 34 emulator, ...)
// this function returns a query to make a view with a column "dblist" of type
// INTEGER, as expected. On the Google Pixel 8a with android 14, and on API 35
// emulators, the column "dblist" is of type BLOB, which is not correct
String NNN_DATE_VIEW_QUERY = Task.CREATE_SECTIONED_DATE_VIEW(listId);
DatabaseHandler
.getInstance(getContext())
.getWritableDatabase()
.execSQL(NNN_DATE_VIEW_QUERY);

// this cursor contains the real notes (read from the database)
// and some "artificial" records used as headers for the groups of notes
result = DatabaseHandler
.getInstance(getContext())
.getReadableDatabase()
Expand All @@ -466,6 +478,10 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s
Task.SECRET_TYPEID + "," + Task.Columns.DUE + ","
+ Task.SECRET_TYPEID2);

// You can see that the cursor contains both fake records like "today+1"
// and real notes taken from the database
// String DBG_READABLE_CURSOR_DUMP = DatabaseUtils.dumpCursorToString(result);

result.setNotificationUri(getContext().getContentResolver(),
Task.URI);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ public Loader<Cursor> onCreateLoader(int id, Bundle arg1) {
String[] whereArgs;

if (mListId > 0) {
where = Task.Columns.DBLIST + " IS ?";
// Fix for issue #525 which is caused by some android versions (API 35
// emulator, Google Pixel 8a on Android 14, ...) incorrectly generating
// the dblist column (=Task.Columns.DBLIST) as BLOB instead of INTEGER.
// So we cast its value to INTEGER to restore the (expected) behavior
// of older android versions
where = "CAST(" + Task.Columns.DBLIST + " AS INTEGER) IS ?";
whereArgs = new String[] { Long.toString(mListId) };
} else {
targetUri = Task.URI;
Expand Down

0 comments on commit f37d8f0

Please sign in to comment.