顺序插入在机器人数据库 [英] Order of insert in android database

查看:117
本文介绍了顺序插入在机器人数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么可以插入一个元素在数据库的开始?我想这样做的原因是: 一)我想显示的元件(ListView的)为最后一插在顶部和底部第一插入'(象一个栈) b)本人希望限制在我的分贝元素的量。当一个新的元素添加(超过限制),我可以把新的(开头),并删除最后一个。 (还不知道如何删除最后一个元素)。

I am wondering how can I insert an element at the beginning of the data base? I want to do this because: a) I want to display the elements (ListView) as 'last-inserted on top and first-inserted on the bottom' (like a stack) b) I want to limit the amount of elements in my db. When a new element is added (over the limit) I can put the new one (at the beginning) and delete the last one. (Don't know yet how to delete the last element).

我正在寻找一个解决方案,但我开始怀疑我有这个元素如何被插入任何控制。如果不是我在想从最终显示数据库底部。但真的不知道该怎么做,因为光标始终设置在DB的开始。如果能做到这一点,我可以解决b)删去第一个元素(同样不知道如何实现这一目标还)。

I was searching for a solution but I am starting to wonder I have any control of how the element are inserted. If not I was thinking about displaying the database from end to bottom. But don't actually know how to do it since the cursor is always set at the beginning of the db. If could achieve this I can solve b) by deleting the first element (again don't know how to achieve this yet).

推荐答案

每一个SQLite表中的每一行都有一个64位有符号整数键唯一标识的表中的行。这个整数通常被称为ROWID

Every row of every SQLite table has a 64-bit signed integer key that uniquely identifies the row within its table. This integer is usually called the "rowid"

要获得最后插入顶部和第一插入底部....

To get last inserted at top and first inserted at bottom....

SELECT * from mytable order by ROWID desc;

了解更多关于ROWID 这里

和,删除最旧的:

DELETE from mytable WHERE ROWID = (SELECT MIN(ROWID) FROM mytable);

如果您使用的ROWID,你不必修改现有的表。和,ROWID值是保证。

If you use the ROWID, you do not have to modify your existing table. And, the value of ROWID is guaranteed.

这篇关于顺序插入在机器人数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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