I'm developing a system in C that commits updates into a MySQL database. The client isn't always online and therefore the application will save the SQL commands that would be executed into a *.sql when the server is inaccessible.
I'm thinking of adding a BOOLEAN field named late_commit
to the tables used so I’ll know that those were inserted into the database later when the connection was restored.
I could alter the programming logic within the program to include the late_commit
field in the insert queries but I’d rather have it with a default value of false and somehow have it set to true only when the .sql file is be executed.
I thought of intercalating the inserts with alter statements, but this seems a bit clumsy and will offer poor performance.
I've never used triggers but from what I see in this SO question they could work. They seem, however, not to be temporary or local to the session, which would interfere with the concurrent inserts from other clients.
Do you have any idea on how you did/would do this? Not necessarily the query(ies) to use, but the technology/approach that would apply the best.
EDIT:
I think that a solution, if no other comes up, could be the creation of a temporary table with the same structure and a late_commit
default to true, insert the data into it, then copy into the main table.
NOTICE: I've added an answer with some approaches that I’ve found. I’m still looking for the permanent solution though. So please if you know how to do it better please comment or answer. thank you!