SQLite 3:按记录排序时的字符问题

发布于 2024-12-10 12:20:24 字数 537 浏览 0 评论 0原文

在我的 SQLite 3 数据库中,我有一些带有土耳其字符的记录,例如“Ö”、“Ü”、“ı”等。当我使用 SELECT * FROM TABLE ORDER BY COLUMN_NAME 查询选择值时,以这些字符开头的记录将出现在最后。

通常,它们应该位于每个字母的无点版本之后。就像“Ö”在“O”之后,“Ü”在“U”之后。

与区域设置有关吗?有没有办法控制这些设置?

我使用 Firefox 中的 SQLite Manager 来管理我的数据库。

提前致谢。

PS我知道这不是SQLite的解决方案,但对于那些需要在Objective-C中使用SQLite DB的人来说,他们可以在从SQLite DB获取数据后对数据数组进行排序。这是一个很好的解决方案:如何使用自定义对 NSMutableArray 进行排序其中的对象?

In my SQLite 3 Database, I have some records with Turkish characters such as "Ö", "Ü", "İ" etc. When I select my values with SELECT * FROM TABLE ORDER BY COLUMN_NAME query, the records that begin with these characters are coming at the end.

Normally, they should've come after the letter that is dot-less version of each. Like "Ö" is after "O", "Ü" is after "U".

Is it something about regional settings? Is there a way to control these settings?

I use SQLite Manager in Firefox to manage my DB.

Thanks in advance.

P.S. I know it's not a solution for SQLite but for those who need to use SQLite DB in Objective-C, they can sort the data array after getting from SQLite DB. Here's a good solution: How to sort an NSMutableArray with custom objects in it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

来世叙缘 2024-12-17 12:20:24

不幸的是,似乎没有直接的解决方案。至少对于 iOS 来说是这样。但有一些方法可以遵循。

在我订阅了 SQLite 的邮件列表后,名为 Jean-Christophe Deschamps 的用户收到了这样的回复:

“在我的 SQLite 3 数据库中,我有一些带有土耳其字符的记录
例如“Ö”、“Ü”、“ı”等。当我使用 'SELECT * FROM 选择我的值时
TABLE ORDER BY COLUMN_NAME'查询,以这些开头的记录
角色将在最后登场。”

裸机 SQLite 仅在较低的 ASCII 字符集上正确进行排序。
虽然这对于简单的英语来说没问题,但对我们大多数人来说却行不通。

“通常情况下,它们应该出现在无点字母之后
每个版本。就像“Ö”在“O”之后,“Ü”在“U”之后。是吗
关于区域设置的一些事情?有没有办法控制这些
设置?”

您可以选择一些方法来使其正确或接近正确
对于您的语言:

o) 使用 ICU 作为扩展(对于第三方管理器)或
链接到
您的申请。
优点:对于给定的语言,它在每个时间点都能 100% 正确地工作。
手术。
缺点:它很大而且很慢,并且需要您注册一个排序规则
您处理的每种语言。它也不适用于列
包含几种非英语语言。

o) 编写您自己的排序规则,调用操作系统的 ICU 例程
整理
字符串。
优点:不会因为庞大的库而使代码变得臃肿。
缺点:需要你编写这个扩展(用 C 或其他语言),同样
与 ICU 一样的其他缺点。

o) 如果您使用 Windows,请下载并使用
扩展一
为接近正确的结果而写。
优点:它很小,相当快并且可以使用,它是语言-
独立但对于许多语言都可以很好地工作
同时;它还提供了许多支持 Unicode 的
字符串操作函数(是否不重音)函数,
模糊搜索功能等等。作为 C 源代码提供
x86 DLL,免费用于任何目的。
缺点:对于任何使用的语言来说,它可能都不能 100% 正确地工作
不仅仅是“普通英文字母”:你的无点我会整理
例如,沿着虚线 i。这是一个很好的折衷方案
一种语言的绝对正确性和“公平”正确性
大多数语言(包括一些使用变音符号的亚洲语言)
下载:http://dl.dropbox.com/u/26433628/unifuzz.zip

“我使用 Firefox 中的 SQLite Manager 来管理我的数据库。”

我的小扩展可以与这个一起使用。您可能还想
尝试内置 ICU 的 SQLite Expert(至少在其专业版中)
还有更多

Unfortunately, it seems there's no direct solution for this. For iOS at least. But there are ways to follow.

After I subscribed to mailing list of SQLite, user Named Jean-Christophe Deschamps came with this reply:

"In my SQLite 3 Database, I have some records with Turkish characters
such as "Ö", "Ü", "İ" etc. When I select my values with 'SELECT * FROM
TABLE ORDER BY COLUMN_NAME' query, the records that begin with these
characters are coming at the end."

Bare bone SQLite only collates correctly on the lower ASCII charset.
While that's fine for plain english, it doesn't work for most of us.

"Normally, they should've come after the letter that is dot-less
version of each. Like "Ö" is after "O", "Ü" is after "U". Is it
something about regional settings? Is there a way to control these
settings?"

You have the choice among some ways to get it right or close to right
for your language(s):

o) use ICU either as an extension (for third-party managers) or
linked to
your application.
Advantages: it works 100% correctly for a given language at a time in each
operation.
Drawbacks: it's huge and slow and it requires you register a collation for
every language you deal with. Also it won't work well for columns
containing several non-english languages.

o) write your own collation(s) invoking your OS' ICU routines to
collate
strings.
Advantages: doesn't bloat your code with huge libraries.
Drawbacks: requires you write this extension (in C or something), same
other drawbacks as ICU.

o) If you use Windows, download and use the functions in the
extension I
wrote for a close-to-correct result.
Advantages: it's small, fairly fast and ready to use, it is language-
independant yet works decently well for many languages at
the same time; it also offers a number of Unicode-aware
string manipulation functions (unaccenting or not) functions,
a fuzzy search function and much more. Comes as a C source and
x86 DLL, free for any purpose.
Drawback: it probably doesn't work 100% correctly for any language using
more than "vanilla english letters": your dotless i will collate
along dotted i, for instance. It's a good compromise between
absolute correctness for ONE language and "fair" correctness for
most languages (including some asian languages using diacritics)
Download: http://dl.dropbox.com/u/26433628/unifuzz.zip

"I use SQLite Manager in Firefox to manage my DB."

My little extension will work with this one. You might also want to
try SQLite Expert which has ICU built-in (at least in its Pro version)
and much more.

Hello爱情风 2024-12-17 12:20:24

这可能是区域设置的问题,但首先我会验证是否使用了 UTF-8 编码。

It could be the regional settings but first I would verify UTF-8 encoding is being used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文