Hi all,
I am getting a strange SQL error which is affected differently depending on which simulator I use.
Here is the original code that is throwing the warning
BOOL executeQueryResults = sqlite3_step(compiledStatement);
if (executeQueryResults == SQLITE_DONE) {
/
/
self.affectedRows = sqlite3_changes(sqlite3Database);
/
self.lastInsertedRowID = sqlite3_last_insert_rowid(sqlite3Database);
}
else {
/
NSLog(@"DB Error: %s", sqlite3_errmsg(sqlite3Database));
}
}I get the warning " Comparison of constant 101 with expression type BOOL is always false".
With this bool statement I get a DB error on iPhone 6.
Now if I change the 'if' statement to :
if (executeQueryResults == true) {Then it works fine with iPhone 6 but no longer with iPhone 5 - the iPhone 5 then throws the same error (DB error).
What am I doing wrong?
The problem is that sqlite3_step() returns an int, not a bool. The value of SQLITE_DONE is 101. When you build for iPhone 6, BOOL is defined as bool and converts any non zero value to 1. In iPhone 5, BOOL is defined as signed char, but doesn't convert the value to 1, hence the error. You either need to change the type of executeQueryResults to int, or just compare directly:
int executeQueryResults = sqlite3_step(compiledStatement);or
if (sqlite3_step(compiledStatement) == SQLITE_DONE) {