diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPCSVParser.m | 2 | ||||
-rw-r--r-- | Source/SPDataImport.m | 12 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 6 | ||||
-rw-r--r-- | Source/SPTableContent.m | 15 | ||||
-rw-r--r-- | Source/SPXMLExporter.m | 4 |
5 files changed, 25 insertions, 14 deletions
diff --git a/Source/SPCSVParser.m b/Source/SPCSVParser.m index 431c89a8..be71b13e 100644 --- a/Source/SPCSVParser.m +++ b/Source/SPCSVParser.m @@ -281,7 +281,7 @@ // Update the total parsed length (differs from parserPosition following trims) totalLengthParsed += parserPosition - startingParserPosition; - // Skip empty rows + // Skip empty rows. Note the NSNull pointer comparison; as [NSNull null] is a singleton this works correctly. if ([csvRowArray count] == 0 || ([csvRowArray count] == 1 && ([csvRowArray objectAtIndex:0] == [NSNull null] diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index 58d132ce..7272948b 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -1394,7 +1394,7 @@ NSInteger colIndex = [[globalVar substringWithRange:[globalVar rangeOfRegex:re capture:1L]] integerValue]; if (colIndex > 0 && colIndex <= (NSInteger)[csvRowArray count]) { id colStr = NSArrayObjectAtIndex(csvRowArray, colIndex-1); - if(colStr == [NSNull null]) + if([colStr isNSNull]) [globalVar replaceCharactersInRange:aRange withString:@"NULL"]; else if([colStr isSPNotLoaded]) [globalVar replaceCharactersInRange:aRange withString:@""]; @@ -1414,7 +1414,7 @@ if ([cellData isSPNotLoaded]) cellData = NSArrayObjectAtIndex(fieldMappingTableDefaultValues, i); - if (cellData == [NSNull null]) { + if ([cellData isNSNull]) { [setString appendString:@"NULL"]; } else { [setString appendString:[mySQLConnection escapeAndQuoteString:cellData]]; @@ -1446,7 +1446,7 @@ NSInteger colIndex = [[globalVar substringWithRange:[globalVar rangeOfRegex:re capture:1L]] integerValue]; if(colIndex > 0 && colIndex <= (NSInteger)[csvRowArray count]) { id colStr = NSArrayObjectAtIndex(csvRowArray, colIndex-1); - if(colStr == [NSNull null]) + if([colStr isNSNull]) [globalVar replaceCharactersInRange:aRange withString:@"NULL"]; else if([colStr isSPNotLoaded]) [globalVar replaceCharactersInRange:aRange withString:@""]; @@ -1466,7 +1466,7 @@ if ([cellData isSPNotLoaded]) cellData = NSArrayObjectAtIndex(fieldMappingTableDefaultValues, i); - if (cellData == [NSNull null]) { + if ([cellData isNSNull]) { [whereString appendString:@" IS NULL"]; } else { [whereString appendString:@"="]; @@ -1521,7 +1521,7 @@ NSInteger colIndex = [[globalVar substringWithRange:[globalVar rangeOfRegex:re capture:1L]] integerValue]; if(colIndex > 0 && colIndex <= (NSInteger)[csvRowArray count]) { id colStr = NSArrayObjectAtIndex(csvRowArray, colIndex-1); - if(colStr == [NSNull null]) + if([colStr isNSNull]) [globalVar replaceCharactersInRange:aRange withString:@"NULL"]; else if([colStr isSPNotLoaded]) [globalVar replaceCharactersInRange:aRange withString:@""]; @@ -1542,7 +1542,7 @@ cellData = NSArrayObjectAtIndex(fieldMappingTableDefaultValues, i); // Insert a NULL if the cell is an NSNull, or is a nullable numeric field and empty - if (cellData == [NSNull null] || ([nullableNumericFieldsMapIndex containsIndex:i] && [[cellData description] isEqualToString:@""])) { + if ([cellData isNSNull] || ([nullableNumericFieldsMapIndex containsIndex:i] && [[cellData description] isEqualToString:@""])) { [valueString appendString:@"NULL"]; } else { diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index 85caa27b..81c1c137 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -292,7 +292,7 @@ static NSString *SPTableViewSqlColumnID = @"sql"; NSMutableArray *globals = [NSMutableArray array]; for(NSUInteger i=0; i < [fieldMappingGlobalValues count]; i++) { id glob = NSArrayObjectAtIndex(fieldMappingGlobalValues, i); - if([NSArrayObjectAtIndex(fieldMappingGlobalValuesSQLMarked, i) boolValue] || glob == [NSNull null]) + if([NSArrayObjectAtIndex(fieldMappingGlobalValuesSQLMarked, i) boolValue] || [glob isNSNull]) [globals addObject:glob]; else [globals addObject:[NSString stringWithFormat:@"'%@'", [(NSString*)glob stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]]]; @@ -839,7 +839,7 @@ static NSString *SPTableViewSqlColumnID = @"sql"; } columnCounter = 0; for(id col in row) { - if(col && col != [NSNull null]) { + if(col && ![col isNSNull]) { if([col isKindOfClass:[NSString class]] && maxLengthOfSourceColumns[columnCounter] < (NSInteger)[(NSString*)col length]) { maxLengthOfSourceColumns[columnCounter] = [(NSString*)col length]; } @@ -1489,7 +1489,7 @@ static NSString *SPTableViewSqlColumnID = @"sql"; fieldMappingArray = [[NSMutableArray alloc] init]; for (i = 0; i < [fieldMappingTableColumnNames count]; i++) { if (i < [NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow) count] - && NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow), i) != [NSNull null]) { + && ![NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow), i) isNSNull]) { value = i; } else { value = 0; diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 948c4eb3..87056e20 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -874,10 +874,14 @@ BOOL rowMatches = NO; for (NSUInteger i = 0; i < tableRowsCount; i++) { + + // For single-column primary keys look up the cell value in the dictionary for a match if (primaryKeyFieldCount == 1) { if ([selectionKeysToRestore objectForKey:SPDataStorageObjectAtRowAndColumn(tableValues, i, primaryKeyFieldIndexes[0])]) { rowMatches = YES; } + + // For multi-column primary keys, convert all the cells to a string for lookup. } else { NSMutableString *lookupString = [[NSMutableString alloc] initWithString:[SPDataStorageObjectAtRowAndColumn(tableValues, i, primaryKeyFieldIndexes[0]) description]]; for (NSUInteger j = 1; j < primaryKeyFieldCount; j++) { @@ -1649,6 +1653,7 @@ // Update data using the new sort order previousTableRowsCount = tableRowsCount; [self setSelectionToRestore:[self selectionDetailsAllowingIndexSelection:NO]]; + [[tableContentView onMainThread] selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO]; [self loadTableValues]; if ([mySQLConnection queryErrored] && ![mySQLConnection lastQueryWasCancelled]) { @@ -1870,7 +1875,7 @@ for ( i = 0 ; i < [dataColumns count] ; i++ ) { column = NSArrayObjectAtIndex(dataColumns, i); - if ([column objectForKey:@"default"] == nil || [column objectForKey:@"default"] == [NSNull null]) { + if ([column objectForKey:@"default"] == nil || [[column objectForKey:@"default"] isNSNull]) { [newRow addObject:[NSNull null]]; } else if ([[column objectForKey:@"default"] isEqualToString:@""] && ![[column objectForKey:@"null"] boolValue] @@ -3719,10 +3724,14 @@ NSMutableDictionary *selectedRowLookupTable = [NSMutableDictionary dictionaryWithCapacity:indexCount]; NSNumber *trueNumber = [NSNumber numberWithBool:YES]; for (NSUInteger i = 0; i < indexCount; i++) { + + // For single-column primary keys, use the cell value as a dictionary key for fast lookups if (primaryKeyFieldCount == 1) { - [selectedRowLookupTable setObject:trueNumber forKey:[SPDataStorageObjectAtRowAndColumn(tableValues, indexBuffer[i], primaryKeyFieldIndexes[0]) description]]; + [selectedRowLookupTable setObject:trueNumber forKey:SPDataStorageObjectAtRowAndColumn(tableValues, indexBuffer[i], primaryKeyFieldIndexes[0])]; + + // For multi-column primary keys, convert all the cell values to a string and use that as the key. } else { - NSMutableString *lookupString = [NSMutableString stringWithString:SPDataStorageObjectAtRowAndColumn(tableValues, indexBuffer[i], primaryKeyFieldIndexes[0])]; + NSMutableString *lookupString = [NSMutableString stringWithString:[SPDataStorageObjectAtRowAndColumn(tableValues, indexBuffer[i], primaryKeyFieldIndexes[0]) description]]; for (NSUInteger j = 1; j < primaryKeyFieldCount; j++) { [lookupString appendString:SPUniqueSchemaDelimiter]; [lookupString appendString:[SPDataStorageObjectAtRowAndColumn(tableValues, indexBuffer[i], primaryKeyFieldIndexes[j]) description]]; diff --git a/Source/SPXMLExporter.m b/Source/SPXMLExporter.m index 8ff99e0d..8393b937 100644 --- a/Source/SPXMLExporter.m +++ b/Source/SPXMLExporter.m @@ -258,7 +258,9 @@ [xmlItem setString:[NSString stringWithString:dataConversionString]]; [dataConversionString release]; - } + } + + // Check for null value using a pointer comparison; as [NSNull null] is a singleton this works correctly. else if (data == [NSNull null]) { dataIsNULL = YES; |