From f7ce31f7cbaac2e4b2e0d9aa06807ba979fe5b1d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 2 Jun 2009 16:22:28 +0000 Subject: [PATCH] Monotone-Parent: fd50c862e356e0c0c102bf3b5901ec2e9de8241e Monotone-Revision: 480d39a8c4def3358ca87a844e455c2ffe987f5f Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2009-06-02T16:22:28 Monotone-Branch: ca.inverse.sogo --- SOPE/GDLContentStore/ChangeLog | 5 +++++ SOPE/GDLContentStore/GCSFolder.h | 2 ++ SOPE/GDLContentStore/GCSFolder.m | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) 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 {