MySQL Forums
Forum List  »  Connector/C (libmysql)

Iterate query and delete rows
Posted by: Theme Park
Date: September 03, 2016 10:20AM

I am developing a program using the C api. I need to execute a SELECT query, iterate through each row, and delete some of the rows.

I couldn't find a way to directly delete the current row, so I'll have to issue a DELETE query, and the SELECT query is too big to fit in memory so I have to use mysql_use_result.

Part of my code is as follows:
while ((row = mysql_fetch_row(result))) {
...
sprintf(sql, "DELETE FROM %s WHERE id=%s", table, row[0]);
mysql_query(conn, sql);
}

But that gives me the error "Commands out of sync; you can't run this command now". So how can I iterate through the SELECT, one row at a time and then possibly delete that row, without having to store the entire result set in memory first?

Options: ReplyQuote


Subject
Views
Written By
Posted
Iterate query and delete rows
589
September 03, 2016 10:20AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.