我有一个sqlitedb,它具有名为symptomtable的表,其中包含ID(整数)和SymptomName(字符串)作为列。我已经创建了一个sqlite查询,其中我正在根据症状名的第一个字母获取症状名称如何从sqlitedb查询中的第一个字符中获取字符串
例如: - ..如果第一个字母包含字母'A'获取这些字,'B'获取这些字等。 。
现在我想从ID逆转过程我想基于第一个字母获取症状名称...如果症状名称从字母'D'开始我想获得从字母'D开始的项目列表'。换句话说我想获取它由第一个字母的从ID ..和返回Indexpath
在查询的NSString * alphabetString = SymptomName列表[的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;
}
为什么你不能以排序的形式获取所有记录。然后通过开始信件分组? – yunas 2013-02-26 17:00:04
尝试从症状中选择*,其中症状如'@ %%''?我不太了解Obj-c查询的语法,但在首字母开头的%字符串'%@ %%'允许其他字符。 – araknoid 2013-02-26 17:01:49
araknoid ..thats我的sqlite声明。 – 2013-02-26 17:05:23