SQLite Forum

sqlite3_column_type wrong
Login

sqlite3_column_type wrong

(1.1) Originally by Gunnar (Couloir) with edits by Richard Hipp (drh) on 2020-08-31 21:04:10 from 1.0 [source]

The sqlite3_column_type function is always returning SQLITE_NULL for me. I've checked that the columns in question have actual values in them.

auto NumColumns = sqlite3_column_count(statement);
for (int c = 0; c < NumColumns; c++)
{
	String ColumnName = sqlite3_column_name(statement, c);
	auto Type = sqlite3_column_type(statement, c);
	auto DeclType = sqlite3_column_decltype( statement, c);
	switch (Type)
	{
		case SQLITE_INTEGER:
			Integer = sqlite3_column_int(statement, c);
			break;

		case SQLITE_FLOAT:

Any help would be greatly appreciated.

(2) By Richard Hipp (drh) on 2020-08-31 21:08:05 in reply to 1.1 [link] [source]

It would appear that you have not yet called [sqlite3_step()][1]. No data has been acquired yet, and so no datatype is available.

Remember that SQLite is more powerful that your typical SQL RDBMS in that it allows the same column to return different types for different rows. Other RDBMSes are limited to a single datatype per column. Because SQLite allows multiple datatypes per column, the datatype is only unique for a particular (row,column) pair. You seem to be asking for the datatype of a column for a null-row, which is always going to come back as NULL.

(3) By Gunnar (Couloir) on 2020-08-31 21:17:18 in reply to 2 [link] [source]

Ahh, thank you. I had the step call in a higher function, but I decided to unit test just the column part.

Now, it works fine!