Reputation: 980
I have a table with TEXT
, INTEGER
, REAL
and other data types.
I wrote a generic sql function to read results for all queries using sqlite3_column_text()
like so:
char *dataAsChar = (char *) sqlite3_column_text(compiledStatement, ii);
Although I should be using sqlite3_column_int
etc. to read the numeric values, the above code seems to work for me. I get the number values as string which I later convert to int using [*numberAsString* intValue]
.
Since I am using a generic function to read all my db values, this is very convenient for me. But is there something that can go wrong with my code?
I could use sqlite3_column_type
for each column to determine the type and use appropriate function. Am I correct in assuming that sqlite3_column_text
basically returns the column value in TEXT
format and does not necessarily need the value itself for be TEXT
?
The only situation where I can see this implementation failing is with BLOB
data type.
Upvotes: 0
Views: 887
Reputation: 180060
The documentation says:
These routines attempt to convert the value where appropriate. […] The following table details the conversions that are applied:
Internal Type Requested Type Conversion NULL TEXT Result is a NULL pointer INTEGER TEXT ASCII rendering of the integer FLOAT TEXT ASCII rendering of the float BLOB TEXT Add a zero terminator if needed
Upvotes: 1