From: helge Date: Fri, 1 Jun 2007 10:37:47 +0000 (+0000) Subject: some improvs on value handling X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8bb2cf785600c52389ed3f159cc9325ee64a1c9;p=sope some improvs on value handling git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1495 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-gdl1/GDLAccess/ChangeLog b/sope-gdl1/GDLAccess/ChangeLog index 5014df42..8eee3a43 100644 --- a/sope-gdl1/GDLAccess/ChangeLog +++ b/sope-gdl1/GDLAccess/ChangeLog @@ -1,3 +1,8 @@ +2007-06-01 Helge Hess + + * EOEntity.m, EOAttribute.m: minor improvements/comments on value + encoding (v4.7.60) + 2007-04-17 Helge Hess * EOSQLExpression.m: fixed a gcc4 warning (v4.7.59) diff --git a/sope-gdl1/GDLAccess/EOAttribute.m b/sope-gdl1/GDLAccess/EOAttribute.m index 8f7b867d..f5147b6e 100644 --- a/sope-gdl1/GDLAccess/EOAttribute.m +++ b/sope-gdl1/GDLAccess/EOAttribute.m @@ -257,34 +257,48 @@ static EONull *null = nil; return nil; if (aValue == null) return aValue; - - // Check if we need conversion; we use is kind of because - // a string is not a NSString but some concrete class, so is NSData, - // NSNumber and may be other classes + + // Check if we need conversion; we use is kind of because + // a string is not a NSString but some concrete class, so is NSData, + // NSNumber and may be other classes if ([aValue isKindOfClass:aClass]) return aValue; - // We have to convert the aValue - - // Try EOCustomValues + // We have to convert the aValue + + // Try EOCustomValues if ([aValue respondsToSelector:@selector(stringForType:)]) { // Special case if aClass is NSNumber if (aClass == [NSNumber class]) { - return [NSNumber - numberWithString:[aValue stringForType:_type] - type:_type]; + return [NSNumber numberWithString:[aValue stringForType:_type] + type:_type]; } // Even more Special case if aClass is NSCalendar date if (aClass == [NSCalendarDate class]) { - id format, date; - + /* we enter this section even if the value is a NSDate object, or + NSCFDate on Cocoa */ + NSCalendarDate *date; + NSString *format; + format = [self calendarFormat]; if (format == nil) format = [EOAttribute defaultCalendarFormat]; - date = [NSCalendarDate - dateWithString:[aValue stringForType:_type] - calendarFormat:format]; + + if ([aValue isKindOfClass:[NSDate class]]) { + // TBD: this does not catch NSCFDate?! + date = [NSCalendarDate dateWithTimeIntervalSince1970: + [(NSDate *)aValue timeIntervalSince1970]]; + } + else { + date = [NSCalendarDate dateWithString:[aValue stringForType:_type] + calendarFormat:format]; + if (date == nil) { + NSLog(@"WARN: could not create NSCalendarDate using format %@ " + @"from value: %@", format, aValue); + } + } + [date setCalendarFormat:format]; return date; } @@ -320,7 +334,7 @@ static EONull *null = nil; - (id)convertValueToModel:(id)aValue { id aValueClassName; Class aValueClass; - + // Check value class from attribute aValueClassName = [self valueClassName]; aValueClass = NSClassFromString(aValueClassName); diff --git a/sope-gdl1/GDLAccess/EOEntity.m b/sope-gdl1/GDLAccess/EOEntity.m index b15a1f9a..8c1a6b71 100644 --- a/sope-gdl1/GDLAccess/EOEntity.m +++ b/sope-gdl1/GDLAccess/EOEntity.m @@ -888,15 +888,15 @@ static inline BOOL _containsObject(NSArray *a, id obj) { NSEnumerator *enumerator; NSString *key; - dict = [NSMutableDictionary dictionary]; + dict = [NSMutableDictionary dictionaryWithCapacity:[aRow count]]; enumerator = [aRow keyEnumerator]; while ((key = [enumerator nextObject]) != nil) { id old = [aRow objectForKey:key]; id new = [[self attributeNamed:key] convertValueToModel:old]; - + if (new != nil) [dict setObject:new forKey:key]; } - + return [dict count] > 0 ? dict : (NSMutableDictionary *)nil; } diff --git a/sope-gdl1/GDLAccess/Version b/sope-gdl1/GDLAccess/Version index de3d3ecd..7fbe8ee1 100644 --- a/sope-gdl1/GDLAccess/Version +++ b/sope-gdl1/GDLAccess/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=59 +SUBMINOR_VERSION:=60