shrimp-hamburger 2013-05-06 03:16 采纳率: 0%
浏览 1982

获取表中列的全部数据

代码我想要获取所有引用数据,一共有320个引用。但是只得到了第一个引用。

-(NSMutableArray *)getAllQuotesData
{
    NSMutableArray *quotesArray = [[NSMutableArray alloc] init];

    NSString *sqlStr = [NSString stringWithFormat:@"SELECT quote FROM quotes"];

    sqlite3_stmt *ReturnStatement = (sqlite3_stmt *) [self getStatement:sqlStr];

    while (sqlite3_step(ReturnStatement)==SQLITE_ROW)
    {
        @try
        {
            QuotesDC *myQuote = [[QuotesDC alloc] init];

             NSString *user_id = [NSString stringWithUTF8String:(char 
*)sqlite3_column_text(ReturnStatement,0)];

             NSString *category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,1)];
             NSString *subcategory = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,2)];
             NSString *quote = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,0)];
             NSString *star = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,4)];

            myQuote.userid = [user_id integerValue];
            myQuote.category = category;
            myQuote.subcategory = subcategory;
            myQuote.quote = quote;
            myQuote.star = star;
            [quotesArray addObject:myQuote];
            NSLog(@"%u", quotesArray.count);
        }
        @catch (NSException *ept) {
            NSLog(@"Exception in %s, Reason: %@", __PRETTY_FUNCTION__, [ept reason]);
        }
        return  quotesArray;
    }

}

  • 写回答

1条回答

  • abcdeFGh_xyz 2013-05-06 08:52
    关注

    代码没有问题哦,只是返回的dataArray在循环外面。你需要加载全部的引用,方法如下:

    -(NSMutableArray *)getAllQuotesData
    {
        NSMutableArray *quotesArray = [[NSMutableArray alloc] init];
    
        NSString *sqlStr = [NSString stringWithFormat:@"SELECT quote FROM quotes"];
    
        sqlite3_stmt *ReturnStatement = (sqlite3_stmt *) [self getStatement:sqlStr];
    
        while (sqlite3_step(ReturnStatement)==SQLITE_ROW)
        {
            @try
            {
                QuotesDC *myQuote = [[QuotesDC alloc] init];
    
                 NSString *user_id = [NSString stringWithUTF8String:(char 
    *)sqlite3_column_text(ReturnStatement,0)];
    
                 NSString *category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,1)];
    
                 NSString *subcategory = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,2)];
    
                 NSString *quote = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,0)];
    
                 NSString *star = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,4)];
    
                myQuote.userid = [user_id integerValue];
                myQuote.category = category;
                myQuote.subcategory = subcategory;
                myQuote.quote = quote;
                myQuote.star = star;
    
                [quotesArray addObject:myQuote];
                NSLog(@"%u", quotesArray.count);
            }
            @catch (NSException *ept) {
                NSLog(@"Exception in %s, Reason: %@", __PRETTY_FUNCTION__, [ept reason]);
            }
        }
    return  quotesArray;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog