diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2022-03-09 17:39:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 17:39:49 (GMT) |
commit | e801e88744f34508aa338f9f7f3f3baee012f813 (patch) | |
tree | ab80307352392818e19b52f609f4436f3ac238d8 /Modules | |
parent | 23dcea5de736b367c0244042aaca10971538b2b4 (diff) | |
download | cpython-e801e88744f34508aa338f9f7f3f3baee012f813.zip cpython-e801e88744f34508aa338f9f7f3f3baee012f813.tar.gz cpython-e801e88744f34508aa338f9f7f3f3baee012f813.tar.bz2 |
bpo-45138: Revert GH-28240: Expand traced SQL statements (GH-31788)
This reverts commit d1777515f9f53b452a4231d68196a7c0e5deb879.
Automerge-Triggered-By: GH:JelleZijlstra
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/connection.c | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 511e8a2..e4b8ecb 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1079,10 +1079,11 @@ progress_callback(void *ctx) * to ensure future compatibility. */ static int -trace_callback(unsigned int type, void *ctx, void *stmt, void *sql) +trace_callback(unsigned int type, void *ctx, void *prepared_statement, + void *statement_string) #else static void -trace_callback(void *ctx, const char *sql) +trace_callback(void *ctx, const char *statement_string) #endif { #ifdef HAVE_TRACE_V2 @@ -1093,46 +1094,24 @@ trace_callback(void *ctx, const char *sql) PyGILState_STATE gilstate = PyGILState_Ensure(); - assert(ctx != NULL); PyObject *py_statement = NULL; -#ifdef HAVE_TRACE_V2 - assert(stmt != NULL); - const char *expanded_sql = sqlite3_expanded_sql((sqlite3_stmt *)stmt); - if (expanded_sql == NULL) { - sqlite3 *db = sqlite3_db_handle((sqlite3_stmt *)stmt); - if (sqlite3_errcode(db) == SQLITE_NOMEM) { - (void)PyErr_NoMemory(); - goto exit; - } - - pysqlite_state *state = ((callback_context *)ctx)->state; - assert(state != NULL); - PyErr_SetString(state->DataError, - "Expanded SQL string exceeds the maximum string " - "length"); - print_or_clear_traceback((callback_context *)ctx); - - // Fall back to unexpanded sql - py_statement = PyUnicode_FromString((const char *)sql); - } - else { - py_statement = PyUnicode_FromString(expanded_sql); - sqlite3_free((void *)expanded_sql); - } -#else - py_statement = PyUnicode_FromString(sql); -#endif + PyObject *ret = NULL; + py_statement = PyUnicode_DecodeUTF8(statement_string, + strlen(statement_string), "replace"); + assert(ctx != NULL); if (py_statement) { PyObject *callable = ((callback_context *)ctx)->callable; - PyObject *ret = PyObject_CallOneArg(callable, py_statement); + ret = PyObject_CallOneArg(callable, py_statement); Py_DECREF(py_statement); - Py_XDECREF(ret); } -exit: - if (PyErr_Occurred()) { - print_or_clear_traceback((callback_context *)ctx); + if (ret) { + Py_DECREF(ret); } + else { + print_or_clear_traceback(ctx); + } + PyGILState_Release(gilstate); #ifdef HAVE_TRACE_V2 return 0; |