Android 上的 SQLite 如何处理长字符串? [英] How SQLite on Android handles long strings?

查看:15
本文介绍了Android 上的 SQLite 如何处理长字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 Android 的 SQLite 实现是如何处理长字符串的.阅读sqlite的在线文档,它说sqlite中的字符串限制为100万个字符.我的字符串肯定更小.

I'm wondering how Android's implementation of SQLite handles long Strings. Reading from online documentation on sqlite, it said that strings in sqlite are limited to 1 million characters. My strings are definitely smaller.

我正在创建一个简单的 RSS 应用程序,在解析 html 文档并提取文本后,我在将其保存到数据库时遇到了问题.我在数据库中有 2 个表,feedsarticles.从 feeds 表中正确保存和检索 RSS 提要,但是当保存到 articles 表时,logcat 说它无法将提取的文本保存到它的列中.我不知道其他列是否也有问题,logcat 中没有提及它们.

I'm creating a simple RSS application, and after parsing a html document, and extracting text, I'm having problem saving it to a database. I have 2 tables in database, feeds and articles. RSS feeds are correctly saved and retrieved from feeds table, but when saving to the articles table, logcat is saying that it cannot save extracted text to it's column. I don't know if other columns are making problems too, no mention of them in logcat.

我想知道,既然文本来自网络上的一篇文章,像 (",',;) 这样的符号是否会产生问题?Android 是否会自动转义它们,或者我必须这样做.我正在使用一种技术插入类似于记事本教程中的一个:

I'm wondering, since text is from an article on web, are signs like (",',;) creating problems? Is Android automaticaly escaping them, or I have to do that. I'm using a technique for inserting similar to one in notepad tutorial:

public long insertArticle(long feedid, String title, String link, String description, String h1,tring h2, String h3, String p, String image, long date) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_FEEDID, feedid);
    initialValues.put(KEY_TITLE, title);
    initialValues.put(KEY_LINK, link);
    initialValues.put(KEY_DESCRIPTION, description );
    initialValues.put(KEY_H1, h1 );
    initialValues.put(KEY_H2, h2);
    initialValues.put(KEY_H3, h3);
    initialValues.put(KEY_P, p);
    initialValues.put(KEY_IMAGE, image);
    initialValues.put(KEY_DATE, date);
    return mDb.insert(DATABASE_TABLE_ARTICLES,null, initialValues);
}

P 列用于提取文本,h1、h2 和 h3 用于页面标题.Logcat 仅报告列 p 是问题.该表是使用以下语句创建的:

Column P is for extracted text, h1, h2 and h3 are for headers from a page. Logcat reports only column p to be the problem. The table is created with following statement:

private static final String DATABASE_CREATE_ARTICLES =
    "create table articles( _id integer primary key autoincrement, feedid integer, title text, link text not null, description text," + "h1 text, h2 text, h3 text, p text, image text, date integer);";

推荐答案

由于 Android 使用 SQLite 作为后端,所有字段都是可变长度的.默认的 sqlite 字段长度限制是 10 亿个字符,但 android 可能已经改变了这一点.

As Android is using SQLite as the backend, all fields are variable length. The default sqlite field length limit is 1 billion chars, but android may have changed this.

这篇关于Android 上的 SQLite 如何处理长字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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