Looks like the sqlite3pp::statement destructor is just processing the result of sqlite3_finalize call. Would it no be safer just to ignore the non SQLITE_OK return, rather then throw an exception from destructor? Looking at documentation for sqlite3_finalize:
“If the most recent evaluation of statement S failed, then sqlite3_finalize(S) returns the appropriate error code or extended error code.”
I guess the same does not apply to the sqlite3pp::transaction destructor. Modifying your example a bit:
Hi,
Looks like the sqlite3pp::statement destructor is just processing the result of sqlite3_finalize call. Would it no be safer just to ignore the non SQLITE_OK return, rather then throw an exception from destructor? Looking at documentation for sqlite3_finalize:
“If the most recent evaluation of statement S failed, then sqlite3_finalize(S) returns the appropriate error code or extended error code.”
I guess the same does not apply to the sqlite3pp::transaction destructor. Modifying your example a bit:
sqlite3pp::transaction xct(db, true); { sqlite3pp::command cmd1( db, "INSERT INTO contacts (name, phone) VALUES (:user, :phone)"); cmd1.bind(":user", "Mike", sqlite3pp::nocopy); cmd1.bind(":phone", "555-1234", sqlite3pp::nocopy); cmd1.execute();
... more code ...
sqlite3pp::command cmd2( db, "INSERT INTO contacts (name, phone) VALUES (:user, :phone)"); cmd2.bind(":user", "Dave", sqlite3pp::nocopy); cmd2.bind(":phone", "555-5678", sqlite3pp::nocopy); cmd2.execute(); } xct.rollback();
If “... more code ...” throws would the xct try to commit the cmd1 part only?
Best Regards, Gorby