-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
bpo-16379: expose SQLite error codes and error names in sqlite3
#27786
bpo-16379: expose SQLite error codes and error names in sqlite3
#27786
Conversation
- Naming: sqlite3ErrName => pysqlite_error_name - Error handling: * return NULL if no exception matched * receiver handles errors * don't use error table to store SQLITE_UNKNOWN string
- Use intermingled declarations - Simplify ref count handling
- Declutter add_error_constants() - No need to typedef struct - Simplify naming - Use PyModule_AddIntConstant
To avoid mismatch between char *name and constant
IMO, we should not pollute the SQLITE_* namespace
- Use correct attribute name - Normalise error variable naming - Remove 'Errno' from printed string to avoid confusion
- Use assertRaisesRegex iso. two assert functions - Normalise quotes - Test that constants are added to the module
cc. @nedbat |
cc. @auvipy & @matrixise who reviewed the original PR. |
FYI, I pushed a small tweak to the unit test: use the Thanks for reviewing, @auvipy |
int | ||
_pysqlite_seterror(pysqlite_state *state, sqlite3 *db) | ||
static PyObject * | ||
get_exception_class(pysqlite_state *state, int errorcode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slighly confusing because normally returning NULL
signifies an error. Could you please document this both on the call site and in this function? Otherwise the call site reads weirdly because
PyObject *exc_class = get_exception_class(state, errorcode);
if (exc_class == NULL) {
return errorcode;
}
seems that is handling an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see now that it can be a bit confusing. I'll add a comment. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Good work!
Thanks Pablo, and you can thank @danielshahaf & @palaviv for the good work; I just "stole" it, rebased onto |
Original PR: GH-1108 (contributed by @palaviv, based on patches by @danielshahaf)
This PR is a rebase and rework of Aviv & Daniel's work.
Co-authored-by: Aviv Pavlivoda
Co-authored-by: Daniel Shahaf
Co-authored-by: Erlend E. Aasland
https://bugs.python.org/issue16379