开发者

how to get database fields value from the sqlite database?

开发者 https://www.devze.com 2022-12-31 05:06 出处:网络
I want to get fields name from the sqlite database in my mac开发者_C百科 desktop application.How it possible please help me.If you\'re using the SQLite C API directly (which you shouldn\'t), you can u

I want to get fields name from the sqlite database in my mac开发者_C百科 desktop application.How it possible please help me.


If you're using the SQLite C API directly (which you shouldn't), you can use the sqlite_column_name() function to get the name of a column for a given index. This works well with the sqlite_column_count() function.

If you're using the Flying Meat Database wrapper (which you should), you can execute PRAGMA table_info(myTable), and then iterate through the ResultSet. The column name is at index 1. In other words:

FMResultSet * infoRS = [db executeQuery:@"PRAGMA table_info(myTable)"];
while ([infoRS next]) {
    NSLog(@"Column #%d: %@", [infoRS intForColumnIndex:0], [infoRS stringForColumnIndex:1]);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号