列数返回零

时间:2014-11-23 08:52:59

标签: ios xcode sqlite

我正在尝试创建从sqlite DB读取的循环,但列计数始终返回零。列= 0

sqlite3_stmt    *statement;

NSString *querySQL =  @"SELECT * FROM Animations";

const char *query_stmt = [querySQL UTF8String];

if (sqlite3_prepare_v2(localDB,query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
    int columns = sqlite3_data_count(statement);
    NSLog(@"Columns: %d",columns);

    while(sqlite3_step(statement) == SQLITE_ROW)
    {
        for (int i=1;i<columns;i++)
        {
        NSString *st0 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, i)];
        NSLog(@"%@",st0);
        }
    }
}

else
{
    NSLog(@"%s","Error on SQLITE_OK");
}

1 个答案:

答案 0 :(得分:1)

https://www.sqlite.org/c3ref/data_count.html

The sqlite3_data_count(P) routine returns 0 if the previous call to sqlite3_step(P) returned SQLITE_DONE. 

尝试将数据计数放在sqlit3_step语句之后(在while循环中)