There's not so hard to add some aggregate functions to Persistence Object,
same as [count]
I think that it will be nice, to get this kind of function :)
+ (NSInteger)aggregateFunc:(NSString *) func onField:(NSString *)field
byCriteria:(NSString *)criteriaString
{
[self tableCheck];
NSInteger countOfRecords;
countOfRecords = 0;
NSString *countQuery;
countQuery = [NSString stringWithFormat:@"SELECT %@(%@) FROM %@ %@",
func, field, [self tableName], criteriaString];
sqlite3 *database = [[SQLiteInstanceManager sharedManager] database];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [countQuery UTF8String], -1, &statement,
nil) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
countOfRecords = sqlite3_column_int(statement, 0);
}
else NSLog(@"Error determining aggregate function of rows in table %@",
[self tableName]);
sqlite3_finalize(statement);
return countOfRecords;
}
Original issue reported on code.google.com by tt.ki...@gmail.com on 22 Apr 2009 at 1:35
Original issue reported on code.google.com by
tt.ki...@gmail.com
on 22 Apr 2009 at 1:35