我是这个数据库编程的新手。我从数据库中检索了单列数据。但我无法从数据库中检索多列数据。
这是我的代码
-(void) readItemsFromDatabaseforTable:(NSString *)tableName {
arrayItems = [[NSMutableArray alloc] init];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
NSString *sql_str = [NSString stringWithFormat:@"select * from %@", tableName];
const char *sqlStatement = (char *)[sql_str UTF8String];
NSLog(@"query %s",sqlStatement);
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *idsstr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
[arrayItems addObject:idsstr];
NSLog(@"*************** %@",arrayItems);
}
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSString *caloriesstr = [NSString stringWithUTF8String:
(char*)sqlite3_column_text(compiledStatement, 4)];
[caloriesarry addObject:caloriesstr];
NSLog(@"naveenkumartesting");
NSLog(@"*************** %@",caloriesarry);
}
}
我的主要目标是从数据库中检索列数据并存储到多个数组中。
请任何人帮助我,