classification
Title: [sqlite3] Fix sqlite3_value_blob() usage
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, erlendaasland, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-02-22 14:37 by erlendaasland, last changed 2021-02-26 11:22 by erlendaasland.

Messages (3)
msg387516 - (view) Author: Erlend Egeberg Aasland (erlendaasland) * Date: 2021-02-22 14:37
The sqlite3_value_*() API is almost identical to the sqlite3_column_*() API. sqlite3_value_bytes() should be called after we've converted the value using sqlite3_value_blob().

See also bpo-43249.
msg387541 - (view) Author: Erlend Egeberg Aasland (erlendaasland) * Date: 2021-02-22 20:13
Related:
If sqlite3_value_blob() returns NULL, we should check if sqlite3_errcode() equals SQLITE_NOMEM and raise MemoryError if it does.

If not, we should initialise cur_py_value to None, because as the PyBytes_FromStringAndSize docs says: "If v is NULL, the contents of the bytes object are uninitialized."
msg387719 - (view) Author: Erlend Egeberg Aasland (erlendaasland) * Date: 2021-02-26 11:22
> If sqlite3_value_blob() returns NULL, we should check if sqlite3_errcode() equals SQLITE_NOMEM and raise MemoryError if it does.

This also applies to sqlite3_value_text().

It also applies to sqlite3_value_bytes() if a conversion takes place. We don't need to care about that as long as we call sqlite3_value_bytes() after conversion.

Also, PyTuple_SetItem() errors are not checked.

I would also suggest using PyUnicode_FromStringAndSize() iso. PyUnicode_FromString() in case SQLITE_TEXT, to avoid the unneeded strlen(). After sqlite3_value_text() is called, we can just use sqlite3_value_bytes(), since the length is precomputed as a result of the conversion.

Berker, would you allow a PR to improve all these issues in _pysqlite_build_py_params(), or would you prefer them split up in multiple PR's?
History
Date User Action Args
2021-02-26 11:22:20erlendaaslandsetmessages: + msg387719
2021-02-26 09:46:13erlendaaslandsettitle: [sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob() -> [sqlite3] Fix sqlite3_value_blob() usage
2021-02-22 20:13:50erlendaaslandsetmessages: + msg387541
2021-02-22 14:37:13erlendaaslandcreate