FMDB 结果集返回 nil
所以事情是这样的,我在我的数据库应用程序中使用 FMDB SQLite Wrapper。我知道绳索数据在那里,但我的数据库真的非常巨大,我想做的就是读取它。不会通过 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];
}
这是用于根据球员的比赛位置搜索球员的IBAction。
-(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];
}
So here is the deal, I am using FMDB SQLite Wrapper for my DB app. I know Cord Data is there but My database is really really huge and all I want to do is read it. No new records are going to be inserted / updated via iOS app. At one point in this app I am trying to pull records from DB which are name of player and thier Id based on searchTerm and searchPosition. searchTerm works perfectly fine. searchPosition query works in sqlite3 but not in iOS app. I don know where I am going wrong. Help me out. Code for both methods are as follows:
-(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];
}
Here is theIBAction used to search players based on their playing position.
-(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];
}
This method just gives selected playing position for search in pickerview.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
self.searchPositionValue = [playingPositions objectAtIndex: row];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试通过打印错误来调试 SQL 语句(在executeQuery:调用之后):
对于开发,我建议启用错误的常规日志记录:
Try to debug the SQL-Statement (after the executeQuery: call) by printing the error:
For developing I would recommend to enable general logging of errors: