这是我的代码:
Db.getInstance().beginTransaction();
int i = Db.getInstance().delete("friends", null, null);
Log.e(TAG, "dropDB: " + i);
Db.getInstance().setTransactionSuccessful();
Db.getInstance().endTransaction();
我搜索了SO社区,但找不到此代码中的错误。当我删除时,i的值是删除的行数,但数据库仍然保持返回行。
Db是我自己的帮助器类,我在其中初始化SQLiteDatabase的对象并得到getWritableDatabase()
。
答案 0 :(得分:0)
可能没什么,但只尝试一次调用getInstance()并将其设置为变量。
答案 1 :(得分:0)
当用户单击btnYES以删除表时,我在CustomDialog中使用它。 我知道该表只有一条记录,因为它有一个密码所以试试这个
db = helper.getReadableDatabase();
String q = "SELECT * FROM masterPW";
Cursor cursor = db.rawQuery(q,null);
// Above query gets TABLE_PW data from Col_IDI
// TABLE_PW will only ever have one row of data
int rowID = 99;
if(cursor.moveToFirst()){
rowID = cursor.getInt(cursor.getColumnIndex(Col_IDI));
str = cursor.getString(cursor.getColumnIndex(Col_MPW));
}
cursor.close();
// Line of code below WORKS deletes entire TABLE <=====
// Not a recommended way to re-set the master password
// db.delete(TABLE_PW, null, null);