Is it possible to iterate over a set of results, and if the condition is met, delete the current row?
i.e. sort of
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)
else
}
rc = sqlite3_step(statement);
}
sqlite3_finalize(statement);
sqlite3_exec(db, "COMMIT", 0, 0, 0);
I could just call a single sql statement to delete all rows that match the criteria, but I don't want to do this if for some reason the failure is turned off.
Is it possible to call an operation to delete the current line?
EDIT: So there is a special column called rowid. Am I just adding this as a column to the previous statement and create another statement like "delete from table, where rowid =?" and pass the current line?
Should this work correctly? Is this the best way around this?
source
share