1

これは私のコードです... 320 引用符を持つすべての引用符データを取得したいのですが、最初の 1 つの引用符しか取得しません。私を助けてください

-(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;
    }
}
4

4 に答える 4

0

このコードを使用してください、これはあなたを助けるかもしれません

-(void)retrivequoteFromDB
{
    NSMutableArray * quoteArray=[[NSMutableArray alloc]init];

    sqlite3 *sqliteDB;

    sqlite3_stmt *compiledStatement = NULL;

    if(sqlite3_open([databasePath UTF8String], &sqliteDB)==SQLITE_OK)
    {
        NSString *sql=@"SELECT quote FROM quotes";

        const char *sqlC=[sql UTF8String];

        if(sqlite3_prepare(sqliteDB, sqlC, -1, &compiledStatement, NULL)==SQLITE_OK)
        {
            while(sqlite3_step(compiledStatement) == SQLITE_ROW)
            {
                NSString *quote = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];

                [quoteArray addObject:quote];
            }
        }
        sqlite3_reset(compiledStatement);
    }
    sqlite3_finalize(compiledStatement);
}
于 2013-05-04T07:33:33.757 に答える