Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 981
Jayprakash Dubey Avatar asked Dec 12 '22 02:12

Jayprakash Dubey


1 Answers

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));
 }
like image 106
Jayprakash Dubey Avatar answered Jan 26 '23 00:01

Jayprakash Dubey