SQLite的获取x行,然后下一个x行 [英] Sqlite Get x rows, then next x rows

查看:193
本文介绍了SQLite的获取x行,然后下一个x行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林开发Android应用程序,它使用SQLite数据库。

Im developing android app, which use SQLite database.

我的的ListView ,它使用的数据从数据库中显示一个列表(见图片)。

I have ListView which uses data from Database to show a list (see picture).

图为德codeD为Base64字符串并存储在数据库中。我的问题是这样的记录:

The picture is decoded in Base64 String and stored in Database. My problem is this Log:

10-19 16:51:36.612: W/CursorWindow(15151): Window is full: 
requested allocation 136877 bytes, free space 78836 bytes, window size 2097152 bytes

这skypes很多帧,因为读取时间长。 这是因为我总是读X + 10行。 第一,它显示的是10行,然后20,然后30,并继续...

It skypes a lot of Frames, because the read time grows. This is because i read always x+10 rows. 1st, it reads 10 rows, then 20, then 30 and go on...

我发现是我所能块中的Base64字符串成多个部分,我不想做的事。

What i found is i can chunk the Base64 String into more parts, what i dont want to do.

我的解决办法是块中的数据。例如,添加函数检测字符串>固定长度,在这种情况下,它存储多个条目的字符串(使用许多行)。 获取功能,然后检测这一点,并重新组装块。 <一href="http://stackoverflow.com/questions/12233049/android-sqlite-database-fails-to-select-a-row-with-a-large-value-throws-illegal?lq=1">SourceLink

My solution was to "chunk" the data. Eg, the "add" function detects if the string is > a fixed length, in which case it stores multiple entries for the string (uses many rows). The "get" function then detects this and re-assembles the chunks. SourceLink

我发现的SQLite数据库有它的极限 SourceLink

I found out that SQLite db has its limits SourceLink.

下一步可能的解决方案是将图像存储到SD卡。我可以在启动过程中做到这一点,就先开始。 SourceLink

Next possible solution is to store images to SDCard. I can do this in initiation process, on the first start. SourceLink

更多信息:链接

解决的办法,我想用的,得到0-10,11行 - 20,21 - 30等。如何实现这一目标?我只需要在SQL查询。

编辑:我的查询

String columns[] = {KEY_ID, KEY_NAME, KEY_RATING, KEY_CUISINE, KEY_IMAGE};
Cursor cursor = db.query(TABLE_RECIPES, columns, null, null, null, null, KEY_NAME, lim);

推荐答案

使用的rawQuery方法,并指定限制关键字。

Use the rawQuery method, and specify the limit keyword.

例如:

"SELECT * FROM myTable limit 10" <-- get the 1st 10 rows
"SELECT * FROM myTable limit 10, 20" <-- get the 2nd 10 rows between 10 and 20, etc

这应该让你开始。

这篇关于SQLite的获取x行,然后下一个x行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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