Passing a column name instead of index in sqlite3
        Posted  
        
            by user271753
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user271753
        
        
        
        Published on 2010-04-19T12:06:39Z
        Indexed on 
            2010/05/23
            23:50 UTC
        
        
        Read the original article
        Hit count: 231
        
The problem code:
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);
In the above code instead of 0 can't I just pass a column name? How can I do that ?
© Stack Overflow or respective owner