私はデータベースを持っています。それには2つのテーブルがあります。 if
の条件で1つのテーブルに電話したいと思います。 if
の条件が満たされない場合、else
部分の2番目のテーブルを呼び出すにはどうすればよいですか?iPhoneの同じデータベースの "ifとelse"部分で異なるテーブルを呼び出す方法は?
これは私が使用するコードです:
{
NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentsDirectory = [Paths objectAtIndex:0];
NSString *Path = [DocumentsDirectory stringByAppendingPathComponent:@"StoreList.sqlite"];
// Open the database from the users filessytem.
if (sqlite3_open([Path UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
//*********const char *sqlStatement = "select * from Store where Zipcode ='%@'",inputTxt ;
NSString *sqlStatement = [NSString stringWithFormat:@"select * from Store where Zipcode ='%@' or Address = '%@' or CityName = '%@'",inputTxt, inputTxt, inputTxt];
NSLog(@" Query in if :%@",sqlStatement);
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array.
if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(@"Latitude:%@",latValue);
NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(@"Longitude:%@",longValue);
//currentLocationLbl.text=[NSString stringWithFormat:@" %@ , %@" ,latValue,longValue];
// delegate.latitudeVal=latValue;
// delegate.longitudeVal=longValue;
txtChangeLocation.text = @"";
isFromChangeLoc=TRUE;
//self.tabBarController.selectedIndex=3;
}
else {
NSLog(@"ELSE PART");
// Open the database from the user's filessytem.
if (sqlite3_open([Path UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
//*********const char *sqlStatement = "select * from Store where Zipcode ='%@'",inputTxt ;
NSString *sqlStatement = [NSString stringWithFormat:@"select * from zipcodes where zip ='35004'"];
NSLog(@" Query in if :%@",sqlStatement);
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSLog(@"Latitude:%@",latValue);
NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSLog(@"Longitude:%@",longValue);
//currentLocationLbl.text=[NSString stringWithFormat:@" %@ , %@" ,latValue,longValue];
// delegate.latitudeVal=latValue;
// delegate.longitudeVal=longValue;
txtChangeLocation.text = @"";
isFromChangeLoc=TRUE;
}
}
}
}
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
}
}
私はテキストボックスから入力を取得しています。データベースにある正しい値を与えると、正常に動作しています。データのフェッチは正しいです。テキストボックスに間違ったデータを入力した場合、正常に動作していない - else
状態が失敗します。
この問題を解決するにはどうすればよいですか?