0
我是這個數據庫編程的新手。我從數據庫中檢索單列數據,但我無法從數據庫檢索多列數據。如何從數據庫中檢索多列數據?
這裏是我的代碼
-(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);
}
}
我的主要目的是從數據庫中檢索列的數據,並存儲到多個陣列。
請你們誰能幫助我,
在我的程序中,我能夠檢索單列數據,但鋤頭檢索多列數據。我嘗試了上述方法但沒有use.please給任何其他解決方案... – kumar 2012-04-23 05:08:09