是否可以遍历一个结果集,如果条件满足,删除当前行?删除sqlite3的当前行,而遍历一个结果集
即像
int rc;
sqlite3_stmt* statement;
sqlite3_exec(db, "BEGIN", 0, 0, 0);
sqlite3_prepare_v2(_db, "SELECT id,status,filename,del FROM mytable", -1, &statement, NULL);
rc = sqlite3_step(statement);
while (rc == SQLITE_ROW){
int id = sqlite3_column_int(statement, 1);
int status = sqlite3_column_int(statement, 2);
const unsigned char* filename = sqlite3_column_int(statement, 3);
int del = sqlite3_column_int(statement, 4);
if (status == 0 || del > 0){
int rc = unlink(filename);
if (rc == 0)
// Now delete the current row
else
// unlink failed, find out why, try again or ... ?
}
rc = sqlite3_step(statement);
}
sqlite3_finalize(statement);
sqlite3_exec(db, "COMMIT", 0, 0, 0);
我可以调用一个sql语句删除符合条件的所有行,但我不想这样做,如果出于某种原因取消链接失败。
我可以调用一个操作来删除当前行?
编辑: 因此,有一个叫ROWID专栏。我只是补充说,作为 先前的语句中的一列,并创建另一个语句,如“从表中删除rowid =?”并传入当前的rowid?
这应该是正确的?这是最好的方法吗?
好的,以及我得到它使用rowid工作。但仍然想知道这是否是最有效的方法。 – Matt 2011-02-08 03:10:10