SQLite Forum

Improve sqlite3_column_name() return value documentation
Login
Software should not be calling sqlite3_column_name() with a NULL statement pointer. This would mean that the return code of the sqlite3_prepare() family of functions was ignored.

Neither knowing nor bothering to check the number of returned columns also strikes me as bad programming practice. If you are executing user composed SQL and returning the results, you must check the number of columns returned (or quit asking on NULL). If you are executing developer-written SQL, then it should be written with an explicit field list (and not SELECT *) for resilience against schema changes. Either way, the number of columns should be known or queried.

Note that the sqlite2_column_<type>() family of functions is explicitly documented to return undefined values if the column index is out of range.