所以这是交易,我正在为我的数据库应用程序使用 FMDB SQLite Wrapper。我知道 Cord Data 在那里,但我的数据库真的非常庞大,我想做的就是阅读它。不会通过 iOS 应用程序插入/更新新记录。在这个应用程序的某一时刻,我试图从数据库中提取记录,这些记录是基于 searchTerm 和 searchPosition 的玩家名称和他们的 ID。searchTerm 工作得很好。searchPosition 查询在 sqlite3 中有效,但在 iOS 应用程序中无效。我不知道我哪里出错了。帮帮我。两种方法的代码如下:
-(IBAction)searchTerm
{
searchTermValue=self.term.text;
self.fmdbUtils = [[[FMDBUtils alloc] initWithDatabase:@"Colts.sql"] autorelease];
FMDatabase *db = [self.fmdbUtils sharedDB];
FMResultSet *rs = nil;
NSString *AgentId = nil;
NSString *PlayerName = nil;
NSString *PlayerId = nil;
ScoutAppDelegate *appDelegate = (ScoutAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.playerList = [[NSMutableArray alloc] init];
NSString * query = @"SELECT * FROM Player WHERE LENGTH (lastname)>0 AND LENGTH (firstname)>0 AND ( lastname LIKE '%' || ? || '%' OR firstname LIKE'%' || ? || '%' OR Height LIKE '%' || ? || '%' OR Weight LIKE '%' || ? || '%') ORDER BY lastname,firstname";
rs = [db executeQuery:query,searchTermValue,searchTermValue,searchTermValue,searchTermValue];
[query release];
while([rs next])
{
PlayerId = [rs stringForColumn:@"player_id"];
//NSString *PlayerName = [rs stringForColumn:@"Player Name"];
if ([rs stringForColumn:@"Player Name"]!= NULL)
{
PlayerName = [rs stringForColumn:@"Player Name"];
}
else
PlayerName=@"";
if ([rs stringForColumn:@"agent_id"]!= NULL)
{
AgentId = [rs stringForColumn:@"agent_id"];
}
else
AgentId=@"0";
Player *temp =[[Player alloc]initPlayerID:PlayerId Name:PlayerName Agent:AgentId];
[appDelegate.playerList addObject:temp];
[temp release];
}
[rs close];
[db close];
PlayersListTableViewController *temp=[[PlayersListTableViewController alloc]initWithNibName:@"PlayersListTableViewController" bundle:nil];
temp.title=@"Players";
self.playersListTableViewCtrl=temp;
[temp release];
[self.navigationController pushViewController:playersListTableViewCtrl animated:YES];
}
这是用于根据玩家位置搜索玩家的 IBA 操作。
-(IBAction)SearchPosition
{
searchTermValue= searchPositionValue;
self.fmdbUtils = [[[FMDBUtils alloc] initWithDatabase:@"Colts.sql"] autorelease];
FMDatabase *db = [self.fmdbUtils sharedDB];
FMResultSet *rs = nil;
NSString *AgentId = nil;
NSString *PlayerName = nil;
NSString *PlayerId = nil;
ScoutAppDelegate *appDelegate = (ScoutAppDelegate *)[[UIApplication sharedApplication] delegate];
//appDelegate.playerList = [[NSMutableArray alloc] init];
NSString * query = @"SELECT * FROM Player WHERE LENGTH (lastname)>0 AND LENGTH (firstname)>0 AND ( College_Position LIKE '%' || ? || '%' OR Pro_Position LIKE'%' || ? || '%') ORDER BY lastname,firstname";
rs = [db executeQuery:query,searchPositionValue,searchPositionValue];
[query release];
while([rs next])
{
PlayerId = [rs stringForColumn:@"player_id"];
//NSString *PlayerName = [rs stringForColumn:@"Player Name"];
if ([rs stringForColumn:@"Player Name"]!= NULL)
{
PlayerName = [rs stringForColumn:@"Player Name"];
}
else
PlayerName=@"";
if ([rs stringForColumn:@"agent_id"]!= NULL)
{
AgentId = [rs stringForColumn:@"agent_id"];
}
else
AgentId=@"0";
Player *temp =[[Player alloc]initPlayerID:PlayerId Name:PlayerName Agent:AgentId];
[appDelegate.playerList addObject:temp];
[temp release];
}
[rs close];
[db close];
PlayersListTableViewController *temp=[[PlayersListTableViewController alloc]initWithNibName:@"PlayersListTableViewController" bundle:nil];
temp.title=@"Players";
self.playersListTableViewCtrl=temp;
[temp release];
[self.navigationController pushViewController:playersListTableViewCtrl animated:YES];
}
此方法仅提供选择的播放位置以在 pickerview 中搜索。
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
self.searchPositionValue = [playingPositions objectAtIndex: row];
}