wxSqlite3 successive commits Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

wxSqlite3 successive commits

Post by raananb »

the code below executes with no errors.
However, when executed twice in a row for two differnet ordinals (with a very small time interval), the first record is deleted, but the second record is not deleted and will show up when the db is reloaded. How do I make sure that the second record is deleted?
wxString command = wxT("DELETE FROM Mouvements WHERE Ordinal = *");
command.Replace(wxT("*"),wxString::Format(wxT("%d"),ordinal));
accountsDB->ExecuteUpdate(command);
wxSQLite3Transaction t(accountsDB);
t.Commit();

(my sql experience is obviously very limited...)
User avatar
doublemax
Moderator
Moderator
Posts: 19162
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSqlite3 successive commits

Post by doublemax »

Code: Select all

wxSQLite3Transaction t(accountsDB);
This line should be above the ExecuteUpdate()
Use the source, Luke!
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

Re: wxSqlite3 successive commits

Post by raananb »

doublemax wrote:

Code: Select all

wxSQLite3Transaction t(accountsDB);
This line should be above the ExecuteUpdate()
Makes no difference.
utelle
Moderator
Moderator
Posts: 1129
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxSqlite3 successive commits

Post by utelle »

raananb wrote:the code below executes with no errors.
However, when executed twice in a row for two differnet ordinals (with a very small time interval), the first record is deleted, but the second record is not deleted and will show up when the db is reloaded. How do I make sure that the second record is deleted?

Code: Select all

wxString command = wxT("DELETE FROM Mouvements WHERE Ordinal = *");
command.Replace(wxT("*"),wxString::Format(wxT("%d"),ordinal));
accountsDB->ExecuteUpdate(command);
wxSQLite3Transaction t(accountsDB);
t.Commit();
Without seeing the code how those statements are executed a second time it's hard to tell which actions take place on the database in the end. It could be that the compiler "optimized" your code resulting in wrong behaviour. The wxSQLite3Transaction constructor implicitly opens a transaction.

I would recommend to explicitly start a transaction (using accountsDB->Begin()) and to explicitly commit (using accountsDB->Commit()) instead o wxSQLite3Transaction.

Additionally I would recommend to use a prepared statement (wxSQLite3Statement) to bind the values of ordinal to your SQL statement.

Regards,

Ulrich
raananb
Super wx Problem Solver
Super wx Problem Solver
Posts: 488
Joined: Fri Oct 27, 2006 4:35 pm
Location: Paris, France
Contact:

Re: wxSqlite3 successive commits

Post by raananb »

Cleaning up the 'ordinal' management solved this problem.

Thanks.
Post Reply