开发者

Store user entered unicode string in sqlite?

My android application allows users to enter strings that later get posted to a web site. I allow the user to enter the string using an EditText field. I take that value and insert it into the sqlite database. The column in sqlite is identified as TEXT.

I have users that complain that the unicode characters that they enter are converted to square characters instead of what 开发者_运维百科they entered.

I saw that sqlite doesn't have unicode conversion tables, but I'm thinking that if the user enters unicode that my application should be able to retrieve it from sqlite and then display it.

Is there something I'm missing? Any guidance on this issue would be helpful.

Thanks!


My issue was due to me omitting the "UTF-8" argument when creating my UrlEncodedFormEntity that posted the web site. The Java and SQLite did the automatic conversion correctly.

This code works:

HttpResponse response = null;
HttpClient client = null;
try {
    final HttpPost post = new HttpPost(url);
final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
post.setEntity(entity);
client = new DefaultHttpClient();
response = client.execute(post);
} catch (IOException e) {
}   


See this entry on how to specify encoding in SQLite. It has to be set prior to data entry, though.

The other thing I can think of is that most likely your insertions are done with literals, not bindings. Am I correct? If you construct your Insert/Update queries, be wary of SQL injection. Binding might actually resolve your Unicode issue.

Finally, I recommend you find a samples from this list of Unicode characters to test your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜