You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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().
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."
changed the title [-][sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob()[/-][+][sqlite3] Fix sqlite3_value_blob() usage[/+]on Feb 26, 2021
changed the title [-][sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob()[/-][+][sqlite3] Fix sqlite3_value_blob() usage[/+]on Feb 26, 2021
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?
Activity
erlend-aasland commentedon Feb 22, 2021
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.
erlend-aasland commentedon Feb 22, 2021
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."
[-][sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob()[/-][+][sqlite3] Fix sqlite3_value_blob() usage[/+][-][sqlite3] sqlite3_value_bytes() should be called after sqlite3_value_blob()[/-][+][sqlite3] Fix sqlite3_value_blob() usage[/+]erlend-aasland commentedon Feb 26, 2021
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?
berkerpeksag commentedon Apr 14, 2021
New changeset 5cb601f by Erlend Egeberg Aasland in branch 'master':
bpo-43296: Handle sqlite3_value_blob() errors (GH-24674)
5cb601f
erlend-aasland commentedon Apr 14, 2021
Thanks, Berker!
I'll add separate issues for sqlite3_value_text() and the missing PyTuple_SetItem() error checks.