更改AIR应用程序SQLite数据库编码设置为UTF-8 [英] Changing SQLite database encoding in AIR app to UTF-8

查看:814
本文介绍了更改AIR应用程序SQLite数据库编码设置为UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个AIR应用程序可以通过flash.data类使用的SQLite。似乎默认创建的数据库的编码设置为UTF-16LE,这意味着,文本数据存储与每个字符的两个字节,产生了近100%的开销对于ASCII重数据库的内容。

In an AIR app you can use SQLite via the flash.data classes. It appears that by default the encoding of the database created is set to UTF-16le, which means that textual data is stored with two bytes per character, resulting in a nearly 100% overhead for ASCII-heavy database content.

默认的SQLite数据库是UTF-8,假设shell程序(sqlite3的)指示。 presumably Adob​​e已决定重写此出于某种原因,但我想preFER不遭受浪费的存储空间,如果可能的。

The default for a SQLite database is UTF-8, assuming the shell program (sqlite3) is indicative. Presumably Adobe has decided to override this for some reason, but I'd prefer not to suffer the wasted storage space if possible.

A PRAGMA编码=UTF-8; 之前的任何内容写入数据库通常会解决这个问题的声明,但它出现的that's不是在AIR 允许无论是。

A PRAGMA encoding = "UTF-8"; statement prior to writing anything to the database would normally resolve the issue, but it appears that's not allowed in AIR either.

我现在变通的做法是使用template.db我创建的时间提前,并捆绑到应用程序中。在这个template.db我已经将编码设置为UTF-8手动。如果数据库文件尚不我的程序启动时存在的,我用这个模板复制到我的数据库文件中创建它,然后继续打开并正常使用。我已经证实,TEXT数据被存储为UTF-8,根据需要。

My workaround for now is to use a "template.db" that I create ahead of time and bundled into the application. In this template.db I've set the encoding to UTF-8 manually. If the database file does not exist already when my program starts, I create it by copying that template to my database file, then proceed to open and use it normally. I've confirmed that TEXT data is then stored as UTF-8, as desired.

我还没有看到任何不良影响呢,但这是的hackish。有没有更好的方法将编码设置为UTF-8?或者是一个坏主意,因为某些原因?

I haven't seen any ill effects yet, but this is hackish. Is there a better way to set the encoding to UTF-8? Or is it a Bad Idea for some reason?

推荐答案

由于没有其他的解决办法或找到答案,我张贴我的解决方法,因为答案。它在过去两年的PlayBook应用程序正常工作,所以presumably没有不可预见的副作用,至少在那样的环境:

我现在变通的做法是使用template.db我创建的时间提前,并捆绑到应用程序中。在这个template.db我已经将编码设置为UTF-8手动。如果数据库文件尚不我的程序启动时存在的,我用这个模板复制到我的数据库文件中创建它,然后继续打开并正常使用。我已经证实,TEXT数据再现在存储为根据需要UTF-8。

My workaround for now is to use a "template.db" that I create ahead of time and bundled into the application. In this template.db I've set the encoding to UTF-8 manually. If the database file does not exist already when my program starts, I create it by copying that template to my database file, then proceed to open and use it normally. I've confirmed that TEXT data then now stored as UTF-8 as desired.

这篇关于更改AIR应用程序SQLite数据库编码设置为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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