Hello, I need some help to do a simple operation, increment a counter and get its former value. I could have some race condition, so the transaction must be atomic.
I also would like to use prepared statements to accomplish that, so I have less effort sanitizing inputs. My problem: I have a counter that I need to increment and get its previous value in one operation. To access this counter I must pass as a parameter to the query a specific WHERE condition. I would like something like this: "BEGIN EXCLUSIVE TRANSACTION;" "SELECT counter FROM mytable WHERE counterid = ?;" "UPDATE mytable SET counter=? WHERE counterid = ?;" "COMMIT TRANSACTION;" The *sqlite3_exec* doesn't allow me to pass parameters. And the documentation of *sqlite3_prepare_v2 *says: "*These routines only compile the first statement in zSql, so *pzTail is left pointing to what remains uncompiled*" My question is: Preparing 4 statements, binding then and calling *sqlite3_step *for each one of then in order, would have the expected atomic operation behavior or not? If not, how could I achieve this? Thank you in advance. Regards. Paulo Roberto. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users