From 92c97653ece581d1697afe9cc26140398d5d81c6 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 30 Jun 2004 15:08:32 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@125 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/ChangeLog | 2 + OGoContentStore/GNUmakefile.preamble | 3 +- OGoContentStore/OCSFolder.h | 3 ++ OGoContentStore/OCSFolder.m | 65 ++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/OGoContentStore/ChangeLog b/OGoContentStore/ChangeLog index e1fd12d8..d23be329 100644 --- a/OGoContentStore/ChangeLog +++ b/OGoContentStore/ChangeLog @@ -1,5 +1,7 @@ 2004-06-30 Helge Hess + * OCSFolder.m: added quick fetches + * GNUmakefile.preamble: fix link path * GNUmakefile (libOGoContentStore_HEADER_FILES_INSTALL_DIR): install diff --git a/OGoContentStore/GNUmakefile.preamble b/OGoContentStore/GNUmakefile.preamble index e99d298a..27075f2c 100644 --- a/OGoContentStore/GNUmakefile.preamble +++ b/OGoContentStore/GNUmakefile.preamble @@ -2,7 +2,8 @@ libOGoContentStore_LIBRARIES_DEPEND_UPON += \ -lGDLAccess \ - -lEOControl + -lEOControl \ + -lSaxObjC OCS_TOOL_LIBS += \ -lOGoContentStore \ diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index f47000dc..c19bec9a 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -26,6 +26,7 @@ #import @class NSString, NSURL, NSNumber, NSArray, NSException; +@class EOQualifier; @class EOAdaptorChannel; @class OCSFolderManager, OCSFolderType, OCSChannelManager; @@ -79,6 +80,8 @@ - (NSString *)fetchContentWithName:(NSString *)_name; - (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name; +- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q; + @end #endif /* __OGoContentStore_OCSFolder_H__ */ diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index d906925b..d8f5939c 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -224,6 +224,71 @@ static BOOL debugOn = YES; userInfo:nil]; } +- (NSString *)columnNameForFieldName:(NSString *)_fieldName { + return _fieldName; +} + +- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q { + EOAdaptorChannel *channel; + NSException *error; + NSMutableString *sql; + NSArray *attrs; + NSMutableArray *results; + NSDictionary *row; + +#if 0 + [self logWithFormat:@"FETCH: %@", _flds]; + [self logWithFormat:@" MATCH: %@", _q]; +#endif + + /* generate SQL */ + + sql = [NSMutableString stringWithCapacity:256]; + [sql appendString:@"SELECT "]; + if (_flds == nil) + [sql appendString:@"*"]; + else { + unsigned i, count; + + count = [_flds count]; + for (i = 0; i < count; i++) { + if (i > 0) [sql appendString:@", "]; + [sql appendString:[self columnNameForFieldName:[_flds objectAtIndex:i]]]; + } + } + [sql appendString:@" FROM "]; + [sql appendString:[self quickTableName]]; + + /* open channel */ + + if ((channel = [self acquireStoreChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open storage channel!"]; + return nil; + } + + /* run SQL */ + + if ((error = [channel evaluateExpressionX:sql]) != nil) { + [self logWithFormat:@"ERROR(%s): cannot execute quick-fetch SQL '%@': %@", + __PRETTY_FUNCTION__, sql, error]; + [self releaseChannel:channel]; + return nil; + } + + /* fetch results */ + + results = [NSMutableArray arrayWithCapacity:64]; + attrs = [channel describeResults]; + while ((row = [channel fetchAttributes:attrs withZone:NULL]) != nil) + [results addObject:row]; + + /* release channels */ + + [self releaseChannel:channel]; + + return results; +} + /* description */ - (NSString *)description { -- 2.39.5