2010-04-19 47 views
3

傳遞一個列名稱,而不是索引問題代碼:在sqlite3的

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

無論如何您都不能使用C綁定。相反,您可以在標準C接口上使用此Objective-C包裝:FMDB