diff --git a/SOPE/GDLContentStore/ChangeLog b/SOPE/GDLContentStore/ChangeLog index 7d27f8619..9093b1b91 100644 --- a/SOPE/GDLContentStore/ChangeLog +++ b/SOPE/GDLContentStore/ChangeLog @@ -1,3 +1,8 @@ +2009-06-02 Wolfgang Sourdeau + + * GCSFolder.m ([GCSFolder -recordsCountByExcludingDeleted:]): new + method that returns the amount of records in a GCS folder. + 2009-03-24 Wolfgang Sourdeau * GCSFolderType.m ([GCSFolderType +folderTypeWithName:_typeName]): diff --git a/SOPE/GDLContentStore/GCSFolder.h b/SOPE/GDLContentStore/GCSFolder.h index a586e9cad..91debe945 100644 --- a/SOPE/GDLContentStore/GCSFolder.h +++ b/SOPE/GDLContentStore/GCSFolder.h @@ -140,6 +140,8 @@ - (void) deleteAclMatchingQualifier: (EOQualifier *) _q; - (void) deleteAclWithSpecification: (EOFetchSpecification *) _fs; +- (unsigned int) recordsCountByExcludingDeleted: (BOOL) includeDeleted; + @end #endif /* __GDLContentStore_GCSFolder_H__ */ diff --git a/SOPE/GDLContentStore/GCSFolder.m b/SOPE/GDLContentStore/GCSFolder.m index 298c7187a..55dd40623 100644 --- a/SOPE/GDLContentStore/GCSFolder.m +++ b/SOPE/GDLContentStore/GCSFolder.m @@ -1291,6 +1291,43 @@ static NSArray *contentFieldNames = nil; } } +- (unsigned int) recordsCountByExcludingDeleted: (BOOL) excludeDeleted +{ + NSMutableString *sqlString; + EOAdaptorChannel *channel; + NSException *error; + NSDictionary *row; + unsigned int count; + NSArray *attrs; + + count = 0; + + sqlString = [NSMutableString stringWithFormat: + @"SELECT COUNT(*) AS CNT FROM %@", + [self storeTableName]]; + if (excludeDeleted) + [sqlString appendString: @" WHERE (c_deleted != 1 OR c_deleted IS NULL)"]; + + channel = [self acquireStoreChannel]; + if (channel) + { + error = [channel evaluateExpressionX: sqlString]; + if (error) + [self errorWithFormat: @"%s: cannot execute SQL '%@': %@", + __PRETTY_FUNCTION__, sqlString, error]; + else + { + attrs = [channel describeResults: NO]; + row = [channel fetchAttributes: attrs withZone: NULL]; + count = [[row objectForKey: @"cnt"] unsignedIntValue]; + [channel cancelFetch]; + } + [self releaseChannel: channel]; + } + + return count; +} + /* description */ - (NSString *)description {