在sqlite3中传递列名而不是索引

时间:2010-04-19 12:06:40

标签: objective-c sqlite iphone-sdk-3.0

问题代码:

NSString *query = @"SELECT Name FROM Category";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil)
        == SQLITE_OK) {
    while (sqlite3_step(statement) == SQLITE_ROW) {
        char *row =(char *)sqlite3_column_text(statement,0);
        char *rowData = (char *)sqlite3_column_text(statement,1);

        NSString *fieldName = [[NSString alloc] initWithUTF8String:row];
        NSString *fieldValue = [[NSString alloc] initWithUTF8String:rowData];
        NSLog(@"%@",fieldName);
        NSLog(@"%@",fieldValue);

        [fieldName release];
        [fieldValue release];
    }
    sqlite3_finalize(statement);
}


char *row =(char *)sqlite3_column_text(statement,0);

在上面的代码而不是0我不能只传递一个列名? 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

你不能,不管C绑定。相反,您可以在标准C接口上使用此Objective-C包装器:FMDB