Oscar Broman
Oscar Broman

Reputation: 1127

Get column type per row

I have a table with a few rows. The datatypes are not set in the table structure and some rows are integers while some are BLOBs.

How would I figure out what's what? I'm using the C API.

sqlite3_column_type gives me the same datatype for all rows, which isn't correct.

Upvotes: 0

Views: 353

Answers (1)

Jan Hudec
Jan Hudec

Reputation: 76256

  1. sqlite3_column_type is the function that gives you the actual type of the data.
  2. Beware that when you get the value with the other sqlite3_column_* functions, sqlite converts the data it has and the type changes to reflect that. Ask for types before doing anything else with the row.
  3. There is some logic that converts values when inserting them. Are you certain the data is what you expect? Check with typeof SQL function (the sqlite3_column_type C function and typeof SQL function should always return the same value).

Upvotes: 1

Related Questions