2013-02-26 63 views
0

我有一個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;  
} 
+0

爲什麼你不能以排序的形式獲取所有記錄。然後通過開始信件分組? – yunas 2013-02-26 17:00:04

+0

嘗試從症狀中選擇*,其中症狀如'@ %%''?我不太瞭解Obj-c查詢的語法,但在首字母開頭的%字符串'%@ %%'允許其他字符。 – araknoid 2013-02-26 17:01:49

+0

araknoid ..thats我的sqlite聲明。 – 2013-02-26 17:05:23

回答

相關問題