У меня есть база данных.В нем две таблицы.Я хочу вызвать одну таблицу в состоянии if
.Как мне вызвать вторую таблицу в части else
, если условия if
не выполнены?
Я использовал этот код:
{
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
не будет выполнено.
Как эту проблему можно исправить?