我在SQLite数据库中有10000多个数据。我试图获取部分数据,比如我试图获取前100条数据记录并存储在数组中,而不是尝试获取接下来的100条数据记录,但我无法进行类似可以获取的查询100记录比获取下100条记录等等.. 这是我的fetchAllData代码
- (void)getAllData {
NSString * convertInttoStr = [NSString stringWithFormat:@"%d", rowNumber];
// Getting the database path.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *dbPath = [docsPath stringByAppendingPathComponent:@"iandroidquran_database 3.sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:dbPath];
[database open];
NSString *sqlSelectQuery = [NSString stringWithFormat:
@"SELECT * FROM qSurahContent WHERE surahID=%@ LIMIT 100 " ,
convertInttoStr];
// Query result
FMResultSet *resultsWithNameLocation = [database executeQuery:sqlSelectQuery];
while([resultsWithNameLocation next]) {
NSString *strID = [NSString stringWithFormat:@"%d",[resultsWithNameLocation intForColumn:@"surahID"]]
[surahContentArabic addObject:strName];
}
if (rowNumber == 1) {
[surahContentArabic removeObjectAtIndex:0];
}
[self.tblView reloadData];
[database close];
}
以下是在tableview中填充它的方法。
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellIdentifier = @"Cell";
NSString * cellIdentifierImage = @"ImageCell";
if(indexPath.row == 0)
{
CustomTableViewCell * cell = [self.tblView dequeueReusableCellWithIdentifier:cellIdentifierImage];
cell.imageView.image = [UIImage imageNamed:@""];
return cell;
}
else
{
CustomTableViewCell * cell = [self.tblView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.surahContenArab.text = [surahContentArabic objectAtIndex:(indexPath.row-1)];
cell.ayahLbl.text = [ayahId objectAtIndex:(indexPath.row-1)];
return cell;
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row + 100 > [self.surahContentArabic count])
{
[self getAllData];
}
}
请告诉我如何获取部分数据的解决方案。感谢
答案 0 :(得分:0)
如果要选择记录100-200
(包括),则必须使用LIMIT OFFSET
子句。
SELECT * FROM qSurahContent WHERE surahID =%@ LIMIT 100 OFFSET 100
以上查询返回100
条记录,从record 101
开始(OFFSET 100)。
您可以更改OFFSET value 200
第3组记录。
希望这有帮助。