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

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

问题描述

在AIR应用程序中,您可以通过flash.data类使用SQLite。看来,默认情况下,创建的数据库的编码设置为UTF-16le,这意味着文本数据以每个字符两个字节存储,导致ASCII重的数据库内容接近100%的开销。

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)是指示性的。大概Adobe已经因为某些原因决定覆盖这一点,但是如果可能的话,我宁愿不要遭受浪费的存储空间。

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.

一个 PRAGMA编码=UTF-8; 语句在写入数据库之前通常会解决问题,但它似乎

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,而不是AIR中的pragma-statement-in-air-app我提前创建并捆绑到应用程序中。在这个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.

我还没有看到任何不良影响,但这是黑客。有没有更好的方法将编码设置为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应用程序中工作得很好,所以可能没有意外的副作用,至少在这种环境中:

我的解决方法现在是使用我之前创建的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天全站免登陆