I have a SQLite database with cyrillic rows in it. For example:
CREATE TABLE customer (
id INTEGER PRIMARY KEY,
name TEXT,
surname TEXT
);
Suppose two of the rows are like this:
"153 | Иван | Попов"
"243 | Ivan | Popov"
It is actually the same name and surname written in russian and english.
I use c++ and Qt in my program. I want to select rows that contain particular string in name or surname columns.
Since I use QSqlTableModel
I simply use filter (which is just WHERE
part of SQL query) with SQL query:
void filterTable(QString filter)
{
QString query;
if(!filter.isEmpty())
{
//I've added the wildcards to be able to search
//using only subset of the name or surname
query += "name LIKE '%" + filter "%' OR ";
query += "surname LIKE '%" + filter "%'";
}
mySqlTableModel->setFilter(query);
}
When I set the filter to 开发者_开发问答'ivan' it shows the correct row (with id 243). However, when I attempt to do the same with 'иван' it does not show, while 'Иван', 'ван' and etc show correct entries. It seems like the query works only with case sensitive matches in cyrillic, while it works perfectly fine with latin letters.
I am aware of ICU and already enabled it. And it works:
$ sqlite3
$ SELECT 'Иван' like 'иван';
1
So I still can not understand why my queries in my program are case sensitive when I use cyrillic letters? Is it somehow related to SQL query implementation in Qt?
By default, SQLite only supports case-insensitivity for ASCII characters. If you want support for Unicode casing, you'll have to define your own UPPER
/LOWER
functions and collation.
精彩评论