我想通过查询获取我组的数据并将它们加载到文本字段中。这是我的表整数 ID 名称文本持续时间实时实时名称列中的名称很少我尝试为每个名称调用方法,但它导致插入失败。
我想收到这个查询并将结果加载到特定标签上:我不知道如何获得响应
SELECT Name,SUM (time) FROM cost GROUP BY Name;
有我当前的代码
NSString *docsDir;
NSArray *dirPaths;
double totaltime = 1.0;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
databasePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"Database.db"]];
NSString *queryString=@"SELECT SUM(DURATION) AS TOTAL FROM RECORDS";
sqlite3_stmt *statement;
if(sqlite3_open([databasePath UTF8String], &myDatabase) == SQLITE_OK) {
if(sqlite3_prepare_v2(myDatabase, [queryString UTF8String], -1, &statement, nil) == SQLITE_OK){
while (sqlite3_step(statement) == SQLITE_ROW) {
totaltime = sqlite3_column_double(statement, 0);
NSLog(@"The sum is %f ", totaltime);
}
}
}
integer_t intotal=totaltime;
NSString* total=[NSString stringWithFormat:@"%d min",intotal];
totaltimefield.text=total;