From: helge Date: Thu, 1 Jul 2004 22:33:30 +0000 (+0000) Subject: git-svn-id: http://svn.opengroupware.org/SOGo/trunk@134 d1b88da0-ebda-0310-925b-ed51d... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=613a6d97b7d04c7258c8c6f735bc26e2eeb1df6d;p=scalable-opengroupware.org git-svn-id: http://svn.opengroupware.org/SOGo/trunk@134 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/OGoContentStore/OCSChannelManager.m b/OGoContentStore/OCSChannelManager.m index 2b568c99..e51f9c4e 100644 --- a/OGoContentStore/OCSChannelManager.m +++ b/OGoContentStore/OCSChannelManager.m @@ -59,7 +59,8 @@ static int ChannelExpireAge = 180; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - debugOn = [ud boolForKey:@"OCSChannelManagerDebugEnabled"]; + debugOn = [ud boolForKey:@"OCSChannelManagerDebugEnabled"]; + debugPools = [ud boolForKey:@"OCSChannelManagerPoolDebugEnabled"]; ChannelExpireAge = [[ud objectForKey:@"OCSChannelExpireAge"] intValue]; if (ChannelExpireAge < 1) ChannelExpireAge = 180; diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index c19bec9a..7453f399 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -25,7 +25,7 @@ #import -@class NSString, NSURL, NSNumber, NSArray, NSException; +@class NSString, NSURL, NSNumber, NSArray, NSException, NSMutableString; @class EOQualifier; @class EOAdaptorChannel; @class OCSFolderManager, OCSFolderType, OCSChannelManager; @@ -82,6 +82,8 @@ - (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q; +- (void)_appendQualifier:(EOQualifier *)_q toString:(NSMutableString *)_ms; + @end #endif /* __OGoContentStore_OCSFolder_H__ */ diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index 402cd22e..3fa18634 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -232,6 +232,103 @@ static BOOL debugOn = YES; return _fieldName; } +/* SQL generation */ + +- (void)_appendAndQualifier:(EOAndQualifier *)_q + toString:(NSMutableString *)_ms +{ + NSArray *qs; + unsigned i, count; + + qs = [_q qualifiers]; + if ((count = [qs count]) == 0) + return; + + for (i = 0; i < count; i++) { + if (i != 0) [_ms appendString:@" AND "]; + if (count > 1) [_ms appendString:@"("]; + [self _appendQualifier:[qs objectAtIndex:i] toString:_ms]; + if (count > 1) [_ms appendString:@")"]; + } +} +- (void)_appendKeyValueQualifier:(EOKeyValueQualifier *)_q + toString:(NSMutableString *)_ms +{ + id val; + + [_ms appendString:[_q key]]; + + if ((val = [_q value])) { + SEL op = [_q selector]; + + if ([val isNotNull]) { + if (sel_eq(op, EOQualifierOperatorEqual)) + [_ms appendString:@" = "]; + else if (sel_eq(op, EOQualifierOperatorNotEqual)) + [_ms appendString:@" != "]; + else if (sel_eq(op, EOQualifierOperatorLessThan)) + [_ms appendString:@" < "]; + else if (sel_eq(op, EOQualifierOperatorGreaterThan)) + [_ms appendString:@" > "]; + else if (sel_eq(op, EOQualifierOperatorLessThanOrEqualTo)) + [_ms appendString:@" <= "]; + else if (sel_eq(op, EOQualifierOperatorGreaterThanOrEqualTo)) + [_ms appendString:@" >= "]; + else if (sel_eq(op, EOQualifierOperatorLike)) + [_ms appendString:@" LIKE "]; + else { + [self logWithFormat:@"ERROR(%s): unsupported operation for null: %@", + __PRETTY_FUNCTION__, NSStringFromSelector(op)]; + } + + if ([val isKindOfClass:[NSNumber class]]) + [_ms appendString:[val stringValue]]; + else if ([val isKindOfClass:[NSString class]]) { + [_ms appendString:@"'"]; + [_ms appendString:val]; + [_ms appendString:@"'"]; + } + else { + [self logWithFormat:@"ERROR(%s): unsupported value class: %@", + __PRETTY_FUNCTION__, NSStringFromClass([val class])]; + } + } + else { + if (sel_eq(op, EOQualifierOperatorEqual)) + [_ms appendString:@" IS NULL"]; + else if (sel_eq(op, EOQualifierOperatorEqual)) + [_ms appendString:@" IS NOT NULL"]; + else { + [self logWithFormat:@"ERROR(%s): invalid operation for null: %@", + __PRETTY_FUNCTION__, NSStringFromSelector(op)]; + } + } + } + else + [_ms appendString:@" IS NULL"]; +} + +- (void)_appendQualifier:(EOQualifier *)_q toString:(NSMutableString *)_ms { + if (_q == nil) return; + + if ([_q isKindOfClass:[EOAndQualifier class]]) + [self _appendAndQualifier:(id)_q toString:_ms]; + else if ([_q isKindOfClass:[EOKeyValueQualifier class]]) + [self _appendKeyValueQualifier:(id)_q toString:_ms]; + else + NSLog(@"ERROR: unknown qualifier: %@", _q); +} +- (NSString *)generateSQLForQualifier:(EOQualifier *)_q { + NSMutableString *ms; + + if (_q == nil) return nil; + ms = [NSMutableString stringWithCapacity:32]; + [self _appendQualifier:_q toString:ms]; + return ms; +} + +/* fetching */ + - (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q { EOAdaptorChannel *channel; NSException *error; @@ -262,7 +359,12 @@ static BOOL debugOn = YES; } [sql appendString:@" FROM "]; [sql appendString:[self quickTableName]]; - + + if (_q != nil) { + [sql appendString:@" WHERE "]; + [sql appendString:[self generateSQLForQualifier:_q]]; + } + /* open channel */ if ((channel = [self acquireStoreChannel]) == nil) { diff --git a/OGoContentStore/README b/OGoContentStore/README index 58588bd3..2fd0d419 100644 --- a/OGoContentStore/README +++ b/OGoContentStore/README @@ -44,10 +44,11 @@ Defaults OCSFolderInfoURL - the DB URL where the folder-info table is located eg: http://OGo:OGo@localhost/test/folder_info - OCSFolderManagerDebugEnabled - enable folder-manager debug logs - OCSFolderManagerSQLDebugEnabled - enable folder-manager SQL gen debug logs + OCSFolderManagerDebugEnabled - enable folder-manager debug logs + OCSFolderManagerSQLDebugEnabled - enable folder-manager SQL gen debug logs - OCSChannelManagerDebugEnabled - enable channel debug pooling logs + OCSChannelManagerDebugEnabled - enable channel debug pooling logs + OCSChannelManagerPoolDebugEnabled - debug pool handle allocation [PGDebugEnabled] - enable PostgreSQL adaptor debugging diff --git a/OGoContentStore/common.h b/OGoContentStore/common.h index edfa4286..8dde8af2 100644 --- a/OGoContentStore/common.h +++ b/OGoContentStore/common.h @@ -24,3 +24,13 @@ #import #include + +#if NeXT_RUNTIME || APPLE_RUNTIME +# define objc_free(__mem__) free(__mem__) +# define objc_malloc(__size__) malloc(__size__) +# define objc_calloc(__cnt__, __size__) calloc(__cnt__, __size__) +# define objc_realloc(__ptr__, __size__) realloc(__ptr__, __size__) +# ifndef sel_eq +# define sel_eq(sela,selb) (sela==selb?YES:NO) +# endif +#endif