2012-01-12 274 views
0

我已经完成了根据给定的主类别id获取子类别的方法。sqlite只返回一条记录

运行此方法时,它只取一条记录。我的意思是控制来到

while(sqlite3_step(selectstmt) == SQLITE_ROW) 

while只循环一次。

当执行相同的查询到SQL浏览器能正常工作并获取结果expected.I不知道为什么这个运行功能不工作时

请让我知道,有什么问题就出在

- (NSMutableDictionary *) getDataToDisplayTierTwo:(NSString*)dbPath:(NSString*)iD{   
    NSMutableDictionary *aTierTwoData = [[NSMutableDictionary alloc]init]; 
    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) 
    { 
     NSString *selectSQL = [NSString stringWithFormat: @"select * from sub_categories_reference scr inner join sub_categories ssc on ssc.id = scr.sub_category_id where scr.main_category_id = %@ ",iD];  
     const char *sql_query_stmt = [selectSQL UTF8String];    
     sqlite3_stmt *selectstmt;   
     if(sqlite3_prepare_v2(database, sql_query_stmt, -1, &selectstmt, NULL) == SQLITE_OK) 
     {    
      while(sqlite3_step(selectstmt) == SQLITE_ROW) 
      { 
       NSLog(@"coming insode"); 
       NSString *aValue = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(selectstmt, 6)];     
       NSString *aId = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(selectstmt, 5)];      
       [aTierTwoData setObject:aId forKey:aValue]; 
       [aValue release]; 
       [aId release];     
       NSLog(@"%@ %@ ^^^^^^^^picker value id ", aValue, aId); 
      } 
     } 
    } 
    else{ 
     //Even though the open call failed, close the database connection to 
     sqlite3_close(database); 
    }   
    return aTierTwoData;   
} 

回答

1
- (NSMutableArray *) getDataToDisplayTierTwo:(NSString*)dbPath:(NSString*)iD{ 

NSMutableDictionary *aTierTwoData = [[NSMutableDictionary alloc]init]; 

NSMutableArray *aTierArray = [[NSMutableArray alloc]init]; 

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) 

{ 
    NSString *selectSQL = [NSString stringWithFormat: @"select * from sub_categories_reference scr inner join sub_categories ssc on ssc.id = scr.sub_category_id where scr.main_category_id = %@ ",iD];  
    const char *sql_query_stmt = [selectSQL UTF8String];    
    sqlite3_stmt *selectstmt;   
    if(sqlite3_prepare_v2(database, sql_query_stmt, -1, &selectstmt, NULL) == SQLITE_OK) 
    {    
     while(sqlite3_step(selectstmt) == SQLITE_ROW) 
     { 
      NSLog(@"coming insode"); 
      NSString *aValue = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(selectstmt, 6)];     
      NSString *aId = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(selectstmt, 5)]; 

      NSLog(@"%@ %@ ^^^^^^^^picker value id ", aValue, aId);     
      [aTierTwoData setObject:aId forKey:aValue]; 
      [aValue release]; 
      [aId release];   

      [aTierArray addObject:aTierTwoData]; 


      aTierTwoData = nil; 

     } 
    } 
} 

else{ 
    //Even though the open call failed, close the database connection to 
    sqlite3_close(database); 
}   
return aTierArray;   
} 
+0

感谢您的答复下面的代码...什么是我的代码 – user198725878 2012-01-12 05:58:05

+0

的问题是它的工作?或不? – Anand 2012-01-12 06:28:01

+0

它不起作用。这也是只返回一条记录 – user198725878 2012-01-12 07:01:35