I’m trying to get integer or bool from database result this way:
bool tblexist = false;
int t_exists = 0;
tblexist = (bool)sqlite3_column_text(chkStmt, 1);
t_exists = atoi(sqlite3_column_text(chkStmt, 1));
… but no one works.
Expected value from sqlite3_column_text(chkStmt, 1) is always 0 or 1.
But I get error message:
invalid conversion from ‘const unsigned char*’ to ‘const char*’
initializing argument 1 of ‘int atoi(const char*)’
||=== Build finished: 2 errors, 0 warnings ===|
How to solve this and get integer or bool on elegant way?
The first line, trying to convert to
boolwill always returntrue, as a string pointer will always be “true” if it’s not NULL. If you want to use this there are a couple of ways to handle this:For the second, try this instead:
This is because
sqlite3_column_textreturns the typeconst unsigned char *butatoiwantsconst char *.