-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Fix possible bugs when setting sqlite3.Connection.isolation_level #72068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a follow up of bpo-27861 and means to fix the second issue mentioned in it. pysqlite_connection_set_isolation_level now does not check allowed values and when any part fails, it leaves the Connection object in an inconsistent state. I'll write a patch trying to fix this tomorrow. |
bpo-27881.patch tires to solve this. Hope to get feedback. |
Serhiy, I've updated the patch. Looking forward to your feedback. |
In general LGTM. But added several style comments. |
Leave replies and make a trival change in v3. I don't change the other two just as I state in the replies. But please do what you like. |
Xiang what do you think about changing the isolation_levels list to begin_statements list:
static const char * const begin_statements[] = {"BEGIN", "BEGIN DEFERRED", "BEGIN IMMEDIATE", "BEGIN EXCLUSIVE", NULL}; This change will allow you to remove all the strings concatenations and the malloc/free. |
I thought about this method but didn't find it's simpler. You cannot avoid malloc/free since the isolation level has to be on heap. It's going to be freed in the dealloc method unless your alter that part too. Then it's about one memcpy or two, which doesn't make much difference. And in this method you have to do more in argument checking. A simple strstr doesn't solve this problem. |
This is interesting suggestion. Indeed, this simplifies the code. Thanks Aviv. |
Hmm, you do this "It's going to be freed in the dealloc method unless your alter that part too". If this is done I admit this is more clean. Patch LGTM. |
What do you think about removing the isolation_level member from the pysqlite_Connection. It is only there to be for the pysqlite_connection_get_isolation_level and that could be easily calculated from the begin_statement. |
Yes, I thought about this. This changes the behavior (for now isolation_level returns exactly the same object that was assigned to it) and slows down the getter. This can be added only on the default branch. |
The only change I see that can happen is that we return upper case isolation level when the user used a lower case. I think that it is worth to slow down the getter for the code simplification. |
New changeset 546b1f70cbed by Serhiy Storchaka in branch '3.5': New changeset 96e05f1af2c8 by Serhiy Storchaka in branch 'default': |
Closing this as 'fixed'. Any further improvement can be discussed in separate issues. Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: