I am developing an iphone application using sqlite. In that, I have a method to retrieve the values from the table which is shown partially.
NSString *sqlQuery = [NSString stringWithFormat: @”select * from %@”, tableName];
If(sqlite3_prepare_v2(db, [sqlQuery UTF8STRING] , -1, &statement, NULL)== SQLITE_OK)
{
While(sqlite3_step(statement) == SQLITE_ROW)
{
}
Sqlite3_finalize(statement);
}
What my doubt is , inside the while loop we can get the values 开发者_如何学Cof the column through the index of the table like the following code.
NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
address.text = addressField;
For one column we can retrieve like this. In my case, I don’t know the number of columns to be retrieved. In this case, how to iterate over the columns. Please help me out. Thanks.
NSString *sqlQuery = [NSString stringWithFormat: @”select * from %@”, tableName];
If(sqlite3_prepare_v2(db, [sqlQuery UTF8STRING] , -1, &statement, NULL)== SQLITE_OK)
{
While(sqlite3_step(statement) == SQLITE_ROW)
{
int columnCount = YouKnowColumnCount;
NSMutableArray* array = [[NSMutableArray alloc]init];
for( int i=0; i<columnCount ; ++i) {
[array addObject:[[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement, i)]];
}
Sqlite3_finalize(statement);
}
Something like this it depend what do you want to do ...
精彩评论