[New-bugs-announce] [issue43249] sqlite3_column_bytes() should be called after sqlite3_column_blob()

Erlend Egeberg Aasland report at bugs.python.org
Thu Feb 18 06:14:23 EST 2021

New submission from Erlend Egeberg Aasland <erlend.aasland at innova.no>:

sqlite3_column_bytes() should be called _after_ sqlite3_column_blob(). There two calls to sqlite3_column_blob() are both preceeded by calls to sqlite3_column_bytes(). Currently it does not do any harm, but it is bad API usage.

I suggest to fix the two cases, and add a comment in the source code as a reminder.


Quoting from https://sqlite.org/c3ref/column_blob.html:
The safest policy is to invoke these routines in one of the following ways:
  * sqlite3_column_text() followed by sqlite3_column_bytes()
  * sqlite3_column_blob() followed by sqlite3_column_bytes()
  * sqlite3_column_text16() followed by sqlite3_column_bytes16()

In other words, you should call sqlite3_column_text(), sqlite3_column_blob(), or sqlite3_column_text16() first to force the result into the desired format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to find the size of the result.

components: Library (Lib)
messages: 387212
nosy: berker.peksag, erlendaasland, serhiy.storchaka
priority: normal
severity: normal
status: open
title: sqlite3_column_bytes() should be called after sqlite3_column_blob()
type: enhancement
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list