使用 OrmLite 在 SqlLite 中组合删除语句几乎没有帮助
我无法在 Android 应用程序中组合删除语句(我正在使用 OrmLite)。
我有一张桌子,里面装满了记录。其中两个字段是“dateCreated”(类型 Date
)和“imageSize”(类型 int
)。在我的代码中,我有一个方法free(int size)
。此方法告诉我,我必须从表中删除总和为“imageSize”<=
大小的最旧记录。
例如..我得到参数1000。每条记录的值可以说是100。这意味着我必须删除10条最旧的记录。
有人可以为我提供最佳的原始 SQL 语句,甚至更好的 OrmLite 代码吗?
我将不胜感激。
I have trouble putting together a delete statement in my Android application (I am using OrmLite).
I have a table filled with records. Two of the fields are "dateCreated" (type Date
) and "imageSize" (type int
). In my code I have a method free(int size)
. This method tells me that I have to delete oldest records from my table that sum "imageSize" <=
size.
For instance .. i get parameter 1000. Each record has value lets say 100. That means i have to delete 10 of the oldest records.
Can some one please provide me with optimal raw SQL statement or even better an OrmLite code for this?
I would be most gratefull.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,您无法使用单个 SQL 语句来完成此操作。没有办法说
您可以执行多个查询,直到找到总和小于 X 的最旧记录,但这需要多次单独的 SQL 调用。
我建议选择最后 X 个图像及其大小,然后使用
DELETE ... IN ...
删除正确数量的图像。这是伪代码:Unfortunately, you can't do this with a single SQL statement. There is no way to say
You could doing multiple queries until you found the oldest records whose sum is less than X but it would take a number of separate SQL calls.
I'd recommend selecting the last X images with their sizes and then doing a delete of the right number of images using a
DELETE ... IN ...
. Here's the pseudo code:试试这个,
为你的函数使用相同的参数
try this,
Use the same parameter for your function