2013-02-26 4 views
0

У меня есть sqlitedb, где у него есть таблица, называемая symomtable, которая содержит идентификатор (Integer) и SymptomName (String) в качестве столбца. Я создал запрос sqlite, где я получаю SymptomName на основе первой буквы симптомаNameКак получить строку из ее первого символа в запросе sqlitedb

для ex: - .. в первой букве содержится буква «A», чтобы получить эти слова, «B» извлечь эти слова и так далее.

Теперь я хочу обратить вспять процесс из ID. Я хочу получить имя-симптом на основе первой буквы ..., если имя симптома начинается с буквы «D», я хочу получить список предметов, который начинается с буквы «D» 'в других случаях я хочу получать список SymptomName, который состоит из первой буквы из ID ..и вернуться Indexpath

в NSString запросов * alphabetString = [NSString stringWithFormat: @ „% с“, я]; из этот код я получаю характер.

-(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;  
} 
+0

Почему бы вам не получить все записи один раз в отсортированной форме. А потом группу, отправив письмо? – yunas

+0

Пробовал 'select * from Symptom где Симптом, как '@ %%''? Я не знаю, правильно ли синтаксис запроса Obj-c, но% в начале строки типа '% @ %%' допускают другие символы перед вашей первой буквой. – araknoid

+0

araknoid .. это мой статус в sqlite. –

ответ

Смежные вопросы