dlang-community / d2sqlite3

A small wrapper around SQLite for the D programming language
Boost Software License 1.0
75 stars 26 forks source link

reset the statement on error #37

Closed tchaloupka closed 7 years ago

tchaloupka commented 7 years ago

Fount this in our multithread app when on

db.execute("BEGIN IMMEDIATE")

it can throw exception because of database is locked by other thread

But after that if one retry the call to the db, it ends up with error: cannot commit transaction - SQL statements in progress.

I found that it is because previous statement of BEGIN IMMEDIATE was not cleared. With this change, it seems to work.

biozic commented 7 years ago

So this could happen whenever an exception is thrown within a method of Statement, couldn't it? This would mean that the statement has to be reset before throwing exceptions in other methods.

tchaloupka commented 7 years ago

You are right. I'll get back to this after vacation. It's this bug for reference: https://issues.dlang.org/show_bug.cgi?id=14246 Fixed in dmd-2.075.0

tchaloupka commented 7 years ago

I forgot this completely :) Until today when I again was hit by this on dmd-2.076.0 again. Looked at the original issue and realized that the fix was reverted and issue reopened.

If I understood this correctly, the only problem is when new structs constructor is called and throws, the structs destructor is not called then. Which is leading to hanging statement reference in this case. Other methods should be fine throwing.

I've looked in the code where Statement is used in the constructor and found only this occurance. So this seems to me good to go.

tchaloupka commented 7 years ago

Actually I think that used statement reset is not needed at all. It just need to not store the statement before exception is thrown.