- (NSMutableArray*)getEmployeeDetailsByEmployeeName:(int)postid
{
NSMutableArray *recordSet = [[NSMutableArray alloc]init];
[self closeanyOpenConnection];
NSString *fetchQuery = [NSString stringWithFormat:@"select * from SubCategory_Content where SubcategoryID==%d",postid];
const char *selectQuery = [fetchQuery UTF8String];
sqlite3_stmt *sqlstatement = nil;
if (sqlite3_prepare_v2(databaseReference, selectQuery, -1, &sqlstatement , NULL)==SQLITE_OK) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
while (sqlite3_step(sqlstatement) == SQLITE_ROW)
{
char* PostIDchar = (char*)sqlite3_column_text(sqlstatement, 1);
NSString *PostID = [NSString stringWithUTF8String:PostIDchar];
[dict setValue:PostID forKey:@"PostID"];
char* ShortContentChar = (char*)sqlite3_column_text(sqlstatement, 2);
NSString *ShortContentStr = [NSString stringWithUTF8String:ShortContentChar];
[dict setValue:ShortContentStr forKey:@"ShortContent"];
char* imageDataFromDatabase = (char*)sqlite3_column_text(sqlstatement, 4);
NSString *ShortContentImage = [NSString stringWithUTF8String:imageDataFromDatabase];
[dict setValue:ShortContentImage forKey:@"ShortContentImage"];
char* titleChar = (char*)sqlite3_column_text(sqlstatement, 5);
NSString *titlestr = [NSString stringWithUTF8String:titleChar];
[dict setValue:titlestr forKey:@"Title"];
[recordSet addObject:dict];
imageDataFromDatabase = nil;
dict = nil;
dict = [[NSMutableDictionary alloc]init];
}
dict = nil;
}
return recordSet;
}
答案 0 :(得分:0)
如果您还没有了解更多详细信息,我建议您在SubcategoryID列上创建一个索引,这样就可以使用sqlite3_exec调用来执行“创建INDEX idx_SubcategoryID ON SubCategory_Content(SubcategoryID ASC)”。
如果事实上查询是您的问题,您应该会看到性能的显着提升。
如果您只是期望查询得到一个结果,那么肯定会在语句末尾添加“LIMIT 1”,但添加了索引可以减轻这种不足。
您还要求它将大量工作存储和检索图像数据作为文本。如果您可以在应用程序中进行这种更改,我建议将它们存储为BLOB值。
首先,我会在SELECT语句周围设置一些断点,看看这实际上是你的减速,很可能是。
由于