开发者

Selecting the values from the database through sqlite in iPhone

开发者 https://www.devze.com 2023-02-28 01:16 出处:网络
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.

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 ...

0

精彩评论

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

关注公众号