How to check a value in a SQLite column is NULL or not with C API?

eonil picture eonil · Jan 22, 2012 · Viewed 8.5k times · Source

I'm using SQLite with C API. On C API, I can check the result value of a column with sqlite3_column_* functions. the problem is there is no function for the case of the value is NULL. Of course, I can check the value with sqlite3_column_bytes function, but it can cause conversion, and I want to avoid conversion at all.

How can I check the value at a column of a row is NULL or not?

Answer

Joachim Isaksson picture Joachim Isaksson · Jan 22, 2012

From what I can remember (and tell from the documentation), the correct way to do it is to use sqlite3_column_type() to check for SQLITE_NULL.

Just be sure to do it before doing anything that may cause conversion of the column.