为什么删除rawQuery需要moveToFirst,以实际删除行? [英] Why does a delete rawQuery need a moveToFirst in order to actually delete the rows?

查看:121
本文介绍了为什么删除rawQuery需要moveToFirst,以实际删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在挣扎了几个小时试图调试为什么下面的删除查询其实并没有删除,即使在同一个数据库完全相同的查询在Firefox'SQLite的经理工作的罚款什么:

I have been struggling for hours trying to debug why the following delete query actually didn't delete anything even if the exact same query on the exact same database worked fine in Firefox' SQLite Manager:

String deleteSql = "DELETE FROM showsummary WHERE url IN (SELECT url FROM showsummary JOIN article_categories USING (url) WHERE categoryid=20 AND title LIKE 'page=%')";
mDb.rawQuery(deleteSql, null);

由于它是一个有点复杂同时具有联接和子查询我的想法盘旋一些限制Android的源码实施有关的子查询,所以我试图简化了查询。但它仍然没有删除任何东西。

Since it is a bit complicated with both a JOIN and a sub query my thoughts circled around some limitations in Android's sqlite implementation regarding sub queries so I tried simplifying the query. But still it didn't delete anything.

后来我改成了一个选择查询(刚刚更换DELETE和SELECT *),且工作。所以也许这不是加入或子查询毕竟是罪魁祸首。

Then I changed it to a select query (just replaced DELETE with SELECT *) and that worked. So probably it was not the join or the sub query that was the culprit after all.

为了测试选择查询我增加了一个 moveToFirst()返回的光标:

In order to test the select query I had added a moveToFirst() to the returned cursor:

mDb.rawQuery(deleteSql, null).moveToFirst();

当我后来改回删除查询一次,我忘了删除 moveToFirst() ,然后它的工作!

When I later changed it back to a delete query again, I forgot to remove the moveToFirst() and then it worked!

这是很好,它的工作原理,但我很困惑为什么要移动光标,以实际删除任何东西。这是设计或者是一个错误?

It's nice that it works now, but I am very confused why it is necessary to move the cursor in order to actually delete anything. Is this by design or is it a bug?

推荐答案

我不能回答为什么,但另一种解决方案是使用.execSQL(字符串)发布的这里

I cannot answer the why, but another solution is to use .execSQL(String) as posted here

这篇关于为什么删除rawQuery需要moveToFirst,以实际删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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