检查SQlite中的文本的编码 [英] Check the encoding of text in SQlite

查看:921
本文介绍了检查SQlite中的文本的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQlite中遇到了与非欧洲文本有关的噩梦。我认为问题是SQlite不是编码的文本在UTF8。所以我想检查编码是什么,并希望将其更改为utf8。我用UTF8编码一个CSV,只是将它导入到SQlite,但非罗马文本是乱码。

I'm having a nightmare dealing with non Eurpean texts in SQlite. I think the problem is that SQlite isn't encoding the text in UTF8. So I want to check what the encoding is, and hopefully change it to utf8. I encoded a CSV in UTF8 and simply imported it to SQlite but the non-roman text is garbled.

我想知道:
1)如何检查编码。
2)如果不是utf8,如何更改编码。我已经阅读了关于Pragma编码,但我不知道如何使用这个。

I would like to know: 1)how to check the encoding. 2)How to change the encoding if it is not utf8. I've been reading about Pragma encoding, but I'm not sure how to use this.

我使用OpenOffice 3创建一个电子表格,半英语和半日语文本。接下来,我使用utf8将文件保存为CSV。这部分似乎是确定。我也试图使用Google文档,它工作正常。接下来我打开SQlite浏览器并做CSV导入。 ENglish文本完全显示,但日语文本是乱码。我想sqlite使用一个dfferent编码(可能是utf16?)。

I used OpenOffice 3 to create a spreadsheet with half ENglish and half Japanese text. Next I saved the file as a CSV using utf8. This part seems to be ok. I also tried to do it using Google Docs and it worked fine. Next I opened SQlite Browser and did CSV import. The ENglish text shows up perfectly, but the Japanese text is garbled symbols. I think sqlite is using a dfferent encoding (perhaps utf16?).

推荐答案

你可以用这个pragma测试编码: p>

You can test the encoding with this pragma:

PRAGMA encoding; 

无法更改现有数据库的编码。要创建具有特定编码的新数据库,请打开与空白文件的SQLite连接,请运行此编译指示:

You cannot change the encoding for an existing database. To create a new database with a specific encoding, open a SQLite connection to a blank file, run this pragma:

PRAGMA encoding = "UTF-8"; 

然后然后创建数据库

如果您有一个数据库,需要不同的编码,那么您需要使用新的编码创建一个新的数据库,然后重新创建模式并导入所有数据。

If you have a database and need a different encoding, then you need to create a new database with the new encoding, and then recreate the schema and import all the data.

然而,如果你有乱码文本的问题,它总是一个问题,使用的工具,而不是SQLite本身。即使SQLite使用不同的编码依赖,唯一的最终结果是,它会导致一些额外的计算,因为SQLite从存储编码转换为API请求的编码不断。如果你使用的不是C级别的API,那么你不应该关心编码 - 你使用的工具使用的API将决定应该使用什么编码。

However, if you have a problem with garbled text it's pretty much always a problem with one of the tools being used, not SQLite itself. Even if SQLite is using a different encoding depending, the only end result is that it will cause some extra computation as SQLite converts from stored encoding to API-requested encoding constantly. If you're using anything other than the C-level API's, then you should never care about encoding--the API's used by the tool you're using will dictate what encoding should be used.

许多SQLite工具显示了将文本从SQLite中删除的问题,包括命令行shell。尝试从命令行运行SQLite并告诉它导入文件本身,而不是通过SQLite浏览器。

Many SQLite tools have shown issues mangling text into our out of SQLite, including command line shells. Try running SQLite from a command line and tell it to import the file itself instead of going through SQLite Browser.

这篇关于检查SQlite中的文本的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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