在 Android SQLite 中使用 COLLATE - LIKE 语句中忽略语言环境 [英] Using COLLATE in Android SQLite - Locales is ignored in LIKE statement

查看:22
本文介绍了在 Android SQLite 中使用 COLLATE - LIKE 语句中忽略语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android 中创建我的 SQLite 数据库时,我设置了数据库区域设置 - db.setLocale(new Locale("cz_CZ")).这是捷克语语言环境.

When creating my SQLite database in Android I set the database locale - db.setLocale(new Locale("cz_CZ")). This is a Czech locale.

SELECT 语句起作用并考虑区域设置,例如:

A SELECT statement works and takes the locale into account, for example:

SELECT * from table WHERE name='sctzy' COLLATE LOCALIZED 

将找到条目ščťžý".

Will find the entry 'ščťžý'.

但是使用 LIKE 会失败:

But using LIKE will fail:

SELECT * from table WHERE name LIKE '%sctzy%' COLLATE LOCALIZED 

没有返回任何行.

顺便说一句.Android 中没有 java.text.Normalized 类.我想我可以用规范化的文本创建第二列,去掉特殊字符,用于搜索 - 但我缺少一个类或如何规范化字符串的方法.

BTW. There is no java.text.Normalized class in Android. I thought I could make a second column with a normalized text, stripped of special characters, which would be used for searching - but I am missing a class or way how to normalize the String.

推荐答案

你看过LIKE 的 SQLite 文档?它提供了有关非 ASCII 字符和错误的信息.也许 Android 安装了旧版本的 SQLite,但这是一个问题.

Have you had a look at the SQLite documentation for LIKE? It has come information about non ASCII characters and a bug. Maybe Android has an older version of SQLite installed where this is a problem.

不幸的是,我认为第二个标准化列可能是您的最佳选择.

I think the second normalised column might be your best option unfortunately.

这篇关于在 Android SQLite 中使用 COLLATE - LIKE 语句中忽略语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆