zdl411437734 / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 0 forks source link

Feature request. #66

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Sorry :) Didn't noticed performSQLAggregation

Original comment by tt.ki...@gmail.com on 22 Apr 2009 at 1:45