aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-23 22:21:23 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-23 22:21:23 +0000
commit24f0afbfe3416b7896d0a3b4f654f04944adf39d (patch)
tree8baf8e6d89d5b57df23b5e88080e8747afaa368b
parented2d754e46bd6a104f1b093b979720727e95dcb5 (diff)
downloadsequelpro-24f0afbfe3416b7896d0a3b4f654f04944adf39d.tar.gz
sequelpro-24f0afbfe3416b7896d0a3b4f654f04944adf39d.tar.bz2
sequelpro-24f0afbfe3416b7896d0a3b4f654f04944adf39d.zip
• added to SPDataAdditions:
- (NSString *) shortStringRepresentationUsingEncoding: --mainly used for displaying large blob data in a tableView • tiny speed improvements for tableView:objectValueForTableColumn and tableView:setObjectValueForTableColumn in Content Browser and Custom Query
-rw-r--r--Source/CustomQuery.m52
-rw-r--r--Source/SPDataAdditions.h1
-rw-r--r--Source/SPDataAdditions.m22
-rw-r--r--Source/TableContent.m40
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 -