diff options
author | rowanbeentje <rowan@beent.je> | 2009-10-10 00:06:52 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-10-10 00:06:52 +0000 |
commit | 0371f943f790d4c20ba5947a90db6cbe41669710 (patch) | |
tree | 53834dfe68b609773a0c9b0f0ccb79b3114a44af /Source/CustomQuery.m | |
parent | a65889bc725c192813f568f606071268693fce5d (diff) | |
download | sequelpro-0371f943f790d4c20ba5947a90db6cbe41669710.tar.gz sequelpro-0371f943f790d4c20ba5947a90db6cbe41669710.tar.bz2 sequelpro-0371f943f790d4c20ba5947a90db6cbe41669710.zip |
Improve handling of NULL and "(not loaded)" placeholders:
- Rewrite TableContent and CustomQuery to store NSNull and SPNotLoaded objects in the data arrays where appropriate, rather than providing string conversion on data load. Faster, simpler comparisons and processing code, slightly lower memory usage, and reduces the chance of bugs caused by inadvertantly processing the string values; we can now also distinguish easily between NULL and "NULL" etc, and further paves the ground for image representations of special values.
- Fix a bug caused by consistent value reloading when editing BLOB/TEXT columns with deferred loading - if editing a row and revisiting an edited cell, the original value was restored; the original value is now only loaded once.
This addresses the rest of Issue #423.
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r-- | Source/CustomQuery.m | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index f04f9fd1..0589ab6f 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -686,13 +686,8 @@ - (void)processResultIntoDataStorage:(MCPStreamingResult *)theResult { NSArray *tempRow; - NSMutableArray *newRow; - int i; long rowsProcessed = 0; - long columnsCount = 0; NSAutoreleasePool *dataLoadingPool; - id prefsNullValue = [[prefs objectForKey:@"NullValue"] retain]; - Class nullClass = [NSNull class]; // Remove all items from the table [fullResult removeAllObjects]; @@ -702,16 +697,8 @@ // Loop through the result rows as they become available while (tempRow = [theResult fetchNextRowAsArray]) { - if (columnsCount == 0) columnsCount = [tempRow count]; NSMutableArrayAddObject(fullResult, [NSMutableArray arrayWithArray:tempRow]); - newRow = NSArrayObjectAtIndex(fullResult, rowsProcessed); - - // Process the retrieved row - for ( i = 0; i < columnsCount; i++ ) { - if ( [NSArrayObjectAtIndex(tempRow, i) isMemberOfClass:nullClass] ) - [newRow replaceObjectAtIndex:i withObject:prefsNullValue]; - } // Update the count of rows processed rowsProcessed++; @@ -725,7 +712,6 @@ // Clean up the autorelease pool [dataLoadingPool drain]; - [prefsNullValue release]; } /* @@ -1182,7 +1168,7 @@ // If there is no primary key, all found fields belonging to the same table are used in the argument for(field in columnsForFieldTableName) { id aValue = [dataRow objectAtIndex:[[field objectForKey:@"datacolumnindex"] intValue]]; - if ([aValue isKindOfClass:[NSNull class]] || [[aValue description] isEqualToString:[prefs stringForKey:@"NullValue"]]) { + if ([aValue isKindOfClass:[NSNull class]] || [aValue isNSNull]) { [fieldIDQueryStr appendFormat:@"%@ IS NULL", [[field objectForKey:@"org_name"] backtickQuotedString]]; } else { [fieldIDQueryStr appendFormat:@"%@=", [[field objectForKey:@"org_name"] backtickQuotedString]]; @@ -1233,11 +1219,8 @@ // For NULL cell's display the user's NULL value placeholder in grey to easily distinguish it from other values if ([cell respondsToSelector:@selector(setTextColor:)]) { - // Note that this approach of changing the color of NULL placeholders is dependent on the cell's value matching that - // of the user's NULL value preference which was set in the result array when it was retrieved (see fetchResultAsArray). - // Also, as an added measure check that the table column actually allows NULLs to make sure we don't change a cell that - // happens to have a value matching the NULL placeholder, but the column doesn't allow NULLs. - [cell setTextColor:([[cell stringValue] isEqualToString:[prefs objectForKey:@"NullValue"]]) ? [NSColor lightGrayColor] : [NSColor blackColor]]; + id theValue = NSArrayObjectAtIndex(NSArrayObjectAtIndex(fullResult, row), [[aTableColumn identifier] intValue]); + [cell setTextColor:[theValue isNSNull] ? [NSColor lightGrayColor] : [NSColor blackColor]]; } } @@ -1255,7 +1238,7 @@ if ( [theValue isKindOfClass:[NSData class]] ) return [theValue shortStringRepresentationUsingEncoding:[mySQLConnection encoding]]; - if ( [theValue isMemberOfClass:[NSNull class]] ) + if ( [theValue isNSNull] ) return [prefs objectForKey:@"NullValue"]; return theValue; @@ -1659,7 +1642,10 @@ && [columnDefinition valueForKey:@"char_length"]) [fieldEditor setTextMaxLength:[[columnDefinition valueForKey:@"char_length"] intValue]]; - id editData = [[fieldEditor editWithObject:[[fullResult objectAtIndex:rowIndex] objectAtIndex:[[aTableColumn identifier] intValue]] + id originalData = [[fullResult objectAtIndex:rowIndex] objectAtIndex:[[aTableColumn identifier] intValue]]; + if ([originalData isNSNull]) originalData = [prefs objectForKey:@"nullValue"]; + + id editData = [[fieldEditor editWithObject:originalData fieldName:[columnDefinition objectForKey:@"name"] usingEncoding:[mySQLConnection encoding] isObjectBlob:isBlob |