diff options
-rw-r--r-- | Source/CustomQuery.m | 52 | ||||
-rw-r--r-- | Source/SPDataAdditions.h | 1 | ||||
-rw-r--r-- | Source/SPDataAdditions.m | 22 | ||||
-rw-r--r-- | Source/TableContent.m | 40 |
4 files changed, 48 insertions, 67 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index ac2d08c7..1a5e3860 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -29,6 +29,7 @@ #import "SPStringAdditions.h" #import "SPTextViewAdditions.h" #import "SPArrayAdditions.h" +#import "SPDataAdditions.h" #import "SPDataCellFormatter.h" #import "TableDocument.h" #import "TablesList.h" @@ -1147,50 +1148,19 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { - id theRow; if ( aTableView == customQueryView ) { - // theRow = [fullResult objectAtIndex:rowIndex]; - // theValue = [theRow objectForKey:[[aTableColumn headerCell] stringValue]]; - // // Convert data objects to their string representation in the current encoding, falling back to ascii - // if ( [theValue isKindOfClass:[NSData class]] ) { - // NSString *dataRepresentation = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]]; - // if (dataRepresentation == nil) - // dataRepresentation = [[NSString alloc] initWithData:theValue encoding:NSASCIIStringEncoding]; - // if (dataRepresentation == nil) { - // theValue = @"- cannot be displayed -"; - // } else { - // if([theValue length] > 255) - // theValue = [NSString stringWithString:dataRepresentation]; - // else - // theValue = [NSString stringWithString:dataRepresentation]; - // // if([theValue length] > 255) - // // theValue = [theValue substringToIndex:255]; - // } - // if (dataRepresentation) [dataRepresentation release]; - // } - // return theValue; - - int theIdentifier = [[aTableColumn identifier] intValue]; - theRow = [queryResult objectAtIndex:rowIndex]; - - if ( [[theRow objectAtIndex:theIdentifier] isKindOfClass:[NSData class]] ) { - NSString *tmp = [[NSString alloc] initWithData:[theRow objectAtIndex:theIdentifier] - encoding:[mySQLConnection encoding]]; - if (tmp == nil) { - tmp = [[NSString alloc] initWithData:[theRow objectAtIndex:theIdentifier] - encoding:NSASCIIStringEncoding]; - } - // If field contains binary data show only the first 255 bytes for speed - if([tmp length] > 255) { - return [[tmp autorelease] substringToIndex:255]; - } else - return [tmp autorelease]; - } - if ( [[theRow objectAtIndex:theIdentifier] isMemberOfClass:[NSNull class]] ) + + id theValue = NSArrayObjectAtIndex(NSArrayObjectAtIndex(queryResult, rowIndex), [[aTableColumn identifier] intValue]); + + if ( [theValue isKindOfClass:[NSData class]] ) + return [theValue shortStringRepresentationUsingEncoding:[mySQLConnection encoding]]; + + if ( [theValue isMemberOfClass:[NSNull class]] ) return [prefs objectForKey:@"NullValue"]; - - return [theRow objectAtIndex:theIdentifier]; + + return theValue; + } else if ( aTableView == queryFavoritesView ) { diff --git a/Source/SPDataAdditions.h b/Source/SPDataAdditions.h index c1c0b389..207921ec 100644 --- a/Source/SPDataAdditions.h +++ b/Source/SPDataAdditions.h @@ -29,5 +29,6 @@ - (NSString *) base64EncodingWithLineLength:(unsigned int)lineLength; - (NSString *) dataToFormattedHexString; +- (NSString *) shortStringRepresentationUsingEncoding:(NSStringEncoding)encoding; @end diff --git a/Source/SPDataAdditions.m b/Source/SPDataAdditions.m index ec91f55c..8018de8a 100644 --- a/Source/SPDataAdditions.m +++ b/Source/SPDataAdditions.m @@ -187,5 +187,27 @@ static char base64encodingTable[64] = { return retVal; } +/* + * Convert data objects to their string representation (max 255 chars) + * in the current encoding, falling back to ascii. (Mainly used for displaying + * large blob data in a tableView) + */ +- (NSString *) shortStringRepresentationUsingEncoding:(NSStringEncoding)encoding +{ + NSString *tmp = [[NSString alloc] initWithData:self encoding:encoding]; + NSString *shortString; + if (tmp == nil) + tmp = [[NSString alloc] initWithData:self encoding:NSASCIIStringEncoding]; + if (tmp == nil) + return @"- cannot be displayed -"; + else { + if([tmp length]>255) + shortString = [[NSString stringWithString:tmp] substringToIndex:255]; + else + shortString = [NSString stringWithString:tmp]; + } + [tmp release]; + return shortString; +} @end diff --git a/Source/TableContent.m b/Source/TableContent.m index 91ecdd53..7327d8bd 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -1971,26 +1971,13 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { - id theRow, theValue; - - theRow = [filteredResult objectAtIndex:rowIndex]; - theValue = [theRow objectForKey:[aTableColumn identifier]]; - - // Convert data objects to their string representation in the current encoding, falling back to ascii - if ( [theValue isKindOfClass:[NSData class]] ) { - NSString *dataRepresentation = [[NSString alloc] initWithData:theValue encoding:[mySQLConnection encoding]]; - if (dataRepresentation == nil) - dataRepresentation = [[NSString alloc] initWithData:theValue encoding:NSASCIIStringEncoding]; - if (dataRepresentation == nil) theValue = @"- cannot be displayed -"; - else { - if([dataRepresentation length]>255) - theValue = [[NSString stringWithString:dataRepresentation] substringToIndex:255]; - else - theValue = [NSString stringWithString:dataRepresentation]; - } - if (dataRepresentation) [dataRepresentation release]; - } - return theValue; + + id theValue = [NSArrayObjectAtIndex(filteredResult, rowIndex) objectForKey:[aTableColumn identifier]]; + + if ( [theValue isKindOfClass:[NSData class]] ) + return [theValue shortStringRepresentationUsingEncoding:[mySQLConnection encoding]]; + + return theValue; } - (void)tableView: (CMCopyTable *)aTableView @@ -2054,15 +2041,16 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn // Catch editing events in the row and if the row isn't currently being edited, // start an edit. This allows edits including enum changes to save correctly. if ( !isEditingRow ) { - [oldRow setDictionary:[filteredResult objectAtIndex:rowIndex]]; + [oldRow setDictionary:NSArrayObjectAtIndex(filteredResult, rowIndex)]; isEditingRow = YES; currentlyEditingRow = rowIndex; } - if ( anObject ) { - [[filteredResult objectAtIndex:rowIndex] setObject:anObject forKey:[aTableColumn identifier]]; - } else { - [[filteredResult objectAtIndex:rowIndex] setObject:@"" forKey:[aTableColumn identifier]]; - } + + if ( anObject ) + [NSArrayObjectAtIndex(filteredResult, rowIndex) setObject:anObject forKey:[aTableColumn identifier]]; + else + [NSArrayObjectAtIndex(filteredResult, rowIndex) setObject:@"" forKey:[aTableColumn identifier]]; + } #pragma mark - |