diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-06-04 18:34:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 18:34:00 (GMT) |
commit | 006fd869e4798b68e266f5de89c83ddb531a756b (patch) | |
tree | 07fc4e96b436ddb2725382cc5ec142f56233bcf4 /Modules/_sqlite | |
parent | 8363ac8607eca7398e568e1336154e1262a995a0 (diff) | |
download | cpython-006fd869e4798b68e266f5de89c83ddb531a756b.zip cpython-006fd869e4798b68e266f5de89c83ddb531a756b.tar.gz cpython-006fd869e4798b68e266f5de89c83ddb531a756b.tar.bz2 |
bpo-43853: Handle sqlite3_value_text() errors (GH-25422)
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/connection.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 47ae9aa..e310dc3 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -550,7 +550,6 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, int i; sqlite3_value* cur_value; PyObject* cur_py_value; - const char* val_str; args = PyTuple_New(argc); if (!args) { @@ -566,15 +565,19 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, case SQLITE_FLOAT: cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value)); break; - case SQLITE_TEXT: - val_str = (const char*)sqlite3_value_text(cur_value); - cur_py_value = PyUnicode_FromString(val_str); - /* TODO: have a way to show errors here */ - if (!cur_py_value) { - PyErr_Clear(); - cur_py_value = Py_NewRef(Py_None); + case SQLITE_TEXT: { + sqlite3 *db = sqlite3_context_db_handle(context); + const char *text = (const char *)sqlite3_value_text(cur_value); + + if (text == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) { + PyErr_NoMemory(); + goto error; } + + Py_ssize_t size = sqlite3_value_bytes(cur_value); + cur_py_value = PyUnicode_FromStringAndSize(text, size); break; + } case SQLITE_BLOB: { sqlite3 *db = sqlite3_context_db_handle(context); const void *blob = sqlite3_value_blob(cur_value); |