#226 Poco::Data Statement problem

open
Data (43)
5
2012-09-14
2008-12-23
Alex Fabijanic
No

Using the Statement class explicitly allows you to reuse the statement when you do inserts, which is great. However, this reuse pattern breaks if during the execution an exception is thrown. When that happens the state (in the "_state" member of the StatementImpl class) is not reset to anything good, so when you try to call execute on the statement again the statement will not execute and simply return.

I'm seeing this when I try to recover from the SQLite::DBLockedException exeption. The statement's state remains to be "bound", so the next time around when I call execute nothing happens. I would classify this as a bug, but I don't claim to have the grand vision of the design...

Just to make it more visual here's a code snippet (note that "record" is a structure with a TypeHandler defined for it):

string addCommand = "INSERT INTO MyTable VALUES(?, ?, ?, ?, ?, ?)";
Statement statement(mySession);
statement << addCommand, use(record);

bool retry = false;
do
{
try
{
statement.execute();
retry = false;
}
catch(SQLite::DBLockedException& unused)
{
retry = true;
Thread::sleep(500);
}
}while(retry);

Kyle

Discussion