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);
兩個問題:源碼得到單列
1)得到單列我必須在循環使用?
2)如果沒有在查詢結果如何警惕「城市找不到」