-
-
Notifications
You must be signed in to change notification settings - Fork 32k
[sqlite3] sqlite3_prepare_v2 micro optimisation: pass string size #88331
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
The signature of sqlite3_prepare_v2 is as follows:
int sqlite3_prepare_v2(
sqlite3 *db, /* Database handle */
const char *zSql, /* SQL statement, UTF-8 encoded */
int nByte, /* Maximum length of zSql in bytes. */
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
const char **pzTail /* OUT: Pointer to unused portion of zSql */
); Quoting from the SQLite docs[1]: sqlite3_prepare_v2 is used five places in the sqlite3 module. We can easily provide the string size in those places. |
Note, PR 26206 does not include statement creation in _pysqlite_connection_begin (Modules/_sqlite/connection.c). That needs further refactoring, so I'll add that in a separate PR if PR 26206 is accepted. |
Regarding the maximum length of an SQL string, quoting from https://sqlite.org/limits.html: The size returned from functions such as PyUnicode_AsUTF8AndSize is Py_ssize_t. I suggest checking the passed SQL string size and raising OverflowError if the SQL string is larger than SQLITE_MAX_LENGTH. |
SQLITE_TOOBIG is currently mapped to sqlite3.DataError. In order to keep the current behaviour, DataError must be raised. |
Erlend, check out #26206 (comment). After that we can close this issue |
See msg393857: I'll add a PR for _pysqlite_connection_begin as well. After that, we can close this. |
IMO, the added complexity is not worth it to change the remaining usages. Closing this issue. |
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: