Jayprakash Dubey Jayprakash Dubey - 4 months ago 33
Objective-C Question

SQLite iOS warning : Comparison of constant 101 with expression of type BOOL is always false

I have downloaded sample code for SQLite learning. I'm using Xcode 6.1.1 and iPhone 6 plus simulator. After running app on simulator I'm getting

DB Error : unknown error
from query execution. Below is part of code where I'm getting warning as
Comparison of constant 101 with expression of type 'BOOL' (aka 'bool') is always false.


// Execute the query.
BOOL executeQueryResults = sqlite3_step(compiledStatement);
if (executeQueryResults == SQLITE_DONE) {
// Keep the affected rows.
self.affectedRows = sqlite3_changes(sqlite3Database);

// Keep the last inserted row ID.
self.lastInsertedRowID = sqlite3_last_insert_rowid(sqlite3Database);
}
else {
// If could not execute the query show the error message on the debugger.
NSLog(@"DB Error: %s", sqlite3_errmsg(sqlite3Database));
}


What might be fix for this?

Screenshot for warning

Answer

Checking condition for compiledStatement directly solved the problem :

// Execute the query.
// BOOL executeQueryResults = sqlite3_step(compiledStatement);
// if (executeQueryResults == SQLITE_DONE) {

 if (sqlite3_step(compiledStatement)) {
     // Keep the affected rows.
      self.affectedRows = sqlite3_changes(sqlite3Database);

      // Keep the last inserted row ID.
       self.lastInsertedRowID = sqlite3_last_insert_rowid(sqlite3Database);
 }
 else {
     // If could not execute the query show the error message on the debugger.
       NSLog(@"DB Error: %s", sqlite3_errmsg(sqlite3Database));
 }