I need to create CursorLoader which will extract all items matching a name and type. What is more name must ignore Locale specific letters (accents). For example, if I provide query with:
item_name LIKE '%cafe%' COLLATE LOCALIZED
then I need then to extract all items, which names contain 'cafe' OR 'café'. I have no idea tho, how to provide COLLATE operator to query built like that (with no plain SQL).
return CursorLoader(
context,
someUri,
arrayOf(
PrompterTable.WORD_C,
PrompterTable.WORD_PLAIN_C,
PrompterTable.ENTRY_ID_C,
PrompterTable.CATEGORY_ID_C,
lengthClause,
PrompterTable.FAVOURITE_C
),
"item_name LIKE ? COLLATE LOCALIZED AND item_type IN (0, 1)",
arrayOf(myItemName),
"L" //alias given to lengthClause before
)
I did set database locale to spanish, I also tryied few ways to build the WHERE statement:
"item_name LIKE ? COLLATE LOCALIZED AND item_type IN (0, 1)"
"(item_name LIKE ? COLLATE LOCALIZED) AND item_type IN (0, 1)"
"item_name LIKE ? AND item_type IN (0, 1) COLLATE LOCALIZED"
"item_name = ? AND item_type IN (0, 1) COLLATE LOCALIZED"
"item_name = ? COLLATE LOCALIZED AND item_type IN (0, 1)"
"(item_name = ? COLLATE LOCALIZED) AND item_type IN (0, 1)"
But every of them won't work I as need (finds only 'cafe'). Query is computed to something like this:
SELECT word, item_name, entryID, item_type, length(word) as L , favourite
FROM item_table
WHERE (item_name LIKE '%cafe%' COLLATE LOCALIZED AND item_type IN (0, 1))
GROUP BY word ORDER BY L LIMIT 25
I tried to reference this topic: Using COLLATE in Android SQLite - Locales is ignored in LIKE statement
But in my case it won't work even with '=' instead of LIKE