Saurabh Jain Saurabh Jain - 3 months ago 8
iOS Question

If Statement give error with sqlite statement in iOS

I am learning the sqlite concept with iOS. At the learning stage I got stuck with with a problem, The problem is:

When i put NSLog after if statement it give no error. See the image:

enter image description here

But when I remove NSLog the compiler give me error, see the image:

enter image description here

Why this error come I have not find yet. My code are:

-(void)runQuery:(const char *)query isQueryExecutable:(BOOL)queryExecutable{
sqlite3 *sqlite3Database;
NSString *databasePath= [self.documentsDirectory stringByAppendingPathComponent:self.databaseFileName];

if(self.arrResults != nil){
[self.arrResults removeAllObjects];
self.arrResults= nil;
}
self.arrResults =[[NSMutableArray alloc] init];

if(self.arrColumnNames != nil){
[self.arrColumnNames removeAllObjects];
self.arrColumnNames= nil;
}
self.arrColumnNames= [[NSMutableArray alloc] init];

BOOL openDatabaseResult= sqlite3_open([databasePath UTF8String],&sqlite3Database);

if(openDatabaseResult==SQLITE_OK)

sqlite3_stmt *compiledStatement;

BOOL prepareStatementResult = sqlite3_prepare_v2(sqlite3Database,query,-1,&compiledStatement,NULL);


}


I am learning the sqlite tutorial from this link: https://www.appcoda.com/sqlite-database-ios-app-tutorial/

Thanks in advance.

Answer

Your issue appears to be that you've forgotten a bracket at the end of the if statement before that line.

if(openDatabaseResult==SQLITE_OK)

{
    sqlite3_stmt *compiledStatement;

    BOOL prepareStatementResult = sqlite3_prepare_v2(sqlite3Database,query,-1,&compiledStatement,NULL);
}
Comments