8000 bpo-44165: optimise sqlite3 statement preparation by passing string size by erlend-aasland · Pull Request #26206 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-44165: optimise sqlite3 statement preparation by passing string size #26206

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

Merged
merged 5 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
sqlite3_limit is cheap; use it directly iso. caching it in the connec…
…tion object
  • Loading branch information
Erlend E. Aasland committed May 19, 2021
commit d0d0618b7713161ab2a88b25075f795ae1ba56e2
3 changes: 0 additions & 3 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
return -1;
}

// Fetch the maximum length of an SQL string or BLOB
self->max_length = sqlite3_limit(self->db, SQLITE_LIMIT_LENGTH, -1);

self->Warning = pysqlite_Warning;
self->Error = pysqlite_Error;
self->InterfaceError = pysqlite_InterfaceError;
Expand Down
3 changes: 0 additions & 3 deletions Modules/_sqlite/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ typedef struct
/* the timeout value in seconds for database locks */
double timeout;

/* the maximum length of an SQL string or BLOB */
int max_length;

/* for internal use in the timeout handler: when did the timeout handler
* first get called with count=0? */
double timeout_started;
Expand Down
5 changes: 4 additions & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,10 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
if (!script_cstr) {
return NULL;
}
if (sql_len >= self->connection->max_length) {

int max_length = sqlite3_limit(self->connection->db,
SQLITE_LIMIT_LENGTH, -1);
if (sql_len >= max_length) {
PyErr_SetString(pysqlite_DataError, "query string is too large");
return NULL;
}
Expand Down
4 changes: 3 additions & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
rc = PYSQLITE_SQL_WRONG_TYPE;
return rc;
}
if (sql_cstr_len >= connection->max_length) {

int max_length = sqlite3_limit(connection->db, SQLITE_LIMIT_LENGTH, -1);
if (sql_cstr_len >= max_length) {
PyErr_SetString(pysqlite_DataError, "query string is too large");
return PYSQLITE_TOO_MUCH_SQL;
}
Expand Down
0