0

我有一个 sqlitedb,其中有一个名为症状表的表,其中包含 ID (Integer) 和 SymptomName(String) 作为列。我创建了一个 sqlite 查询,我在其中根据症状名称的第一个字母获取症状名称

例如:- ..如果第一个字母包含字母“A”获取那些单词,“B”获取那些单词等等..

现在我想从 ID 反转过程我想根据第一个字母获取 symptonName ...如果症状名称从字母“D”开始,我想获取从字母“D”开始的项目列表,换句话说,我想要获取 SymptomName 列表,其中包含来自 ID .. 的第一个字母并返回 Indexpath

在查询 NSString *alphabetString=[NSString stringWithFormat:@"%c",i]; 从这段代码中我得到了字符。

-(NSMutableDictionary *)indexReadData
{
    NSMutableDictionary *indexDict=[[NSMutableDictionary alloc]init];
    int i;  
    NSString *dbPath=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"QuickCureNew1.sqlite"];
    if (sqlite3_open([dbPath UTF8String], &quickAppNew)==SQLITE_OK) 
    {
        for (i=65; i<=90; i++) 
        {
            NSString *alphabetString=[NSString stringWithFormat:@"%c",i];
            NSString *sqlStmtReadIndexSymptom=[NSString stringWithFormat:@"select * from Symptom where Symptom like '%@%%'",alphabetString];
            const char *sqlCharReadIndexSymptom=[sqlStmtReadIndexSymptom UTF8String];
            sqlite3_stmt *selectStmtReadIndexSymptom;
            if (sqlite3_prepare_v2(quickAppNew, sqlCharReadIndexSymptom, -1, &selectStmtReadIndexSymptom, NULL)==SQLITE_OK)
            {
                NSMutableArray *indexArray=[[NSMutableArray alloc] init];
                while (sqlite3_step(selectStmtReadIndexSymptom)==SQLITE_ROW) 
                {
                    indexIdNo=[[NSNumber alloc]initWithInt:(int)sqlite3_column_int(selectStmtReadIndexSymptom,0)];
                    symptomIndexTxt=[[NSString alloc] initWithUTF8String:(char*) sqlite3_column_text(selectStmtReadIndexSymptom, 1)];
                    symptomsIndexDict=[[NSMutableDictionary alloc] initWithObjectsAndKeys: 
                                       symptomIndexTxt,@"SymptIndexName",
                                       indexIdNo,@"SymptIndexID",nil];
                    [indexArray addObject:symptomsIndexDict];
                }
                if (indexArray.count>0) 
                {
                    [indexDict setObject:indexArray forKey:alphabetString];
                }
            }
        }
        sqlite3_close(quickAppNew);
    }
    return indexDict;    
}
4

1 回答 1

0

因为CoreData它是一个NSPredicate

NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'a'"];

这一切都在 Apple Developer 参考中: https ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html

也许这为您指明了正确的方向。

于 2013-02-26T17:58:17.133 回答