문제

I have an alert Use of undeclared identifier 'sql3'.

If I delete the if statement, there 's no problem, but it seems it's not recognized when sql3 is inside the if statement.

Is there a way to fix it?

if ([typedepartie  isEqual: @"ami"]) {

  const char *sql3 = 
        [[NSString stringWithFormat:@"SELECT id 
                                      FROM tabledesquestions 
                                      WHERE pack = ? ORDER BY RANDOM() LIMIT 4"] 
                   cStringUsingEncoding:NSUTF8StringEncoding];

}

listequestionmulti = [[NSMutableArray alloc]init];

sqlite3_stmt *sql1Statement;
if(sqlite3_prepare(database1, sql3, -1, &sql1Statement, NULL) != SQLITE_OK) {
  NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(database1));
}
도움이 되었습니까?

해결책

The identifier sql3 is defined inside curly braces. Therefore it is purely local to those curly braces. Therefore when you get past that to the next part of your code, it no longer exists.

if ([typedepartie  isEqual: @"ami"]) {
   const char *sql3 = // sql3 is born here...;
} // and dies here

What you want is more like this:

char *sql3 = // default value;
if ([typedepartie  isEqual: @"ami"]) {
    sql3 = // other value;
} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top