NSString *cityInput = cityField.text;
NSString *code = @"";
NSString *query = @"SELECT code FROM country WHERE cityname = UPPER(?)";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [query UTF8String],-1, &statement, nil) == SQLITE_OK)
{
sqlite3_bind_text(statement, 1, [cityInput UTF8String], -1, SQLITE_STATIC);
while(sqlite3_step(statement) == SQLITE_ROW) {
code = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
}
}
if(sqlite3_step(statement) != SQLITE_DONE){
NSLog(@"DB: query KO");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ALERT" message:@"City not found" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
return;
}
sqlite3_close(database);
Two questions:
1) for get single row i must use while loop?
2) if there isn’t result in the query how alert “city not found”
1 Answer