diff options
-rw-r--r-- | Source/SPFieldMapperController.h | 3 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 18 | ||||
-rw-r--r-- | Source/TableDump.h | 2 | ||||
-rw-r--r-- | Source/TableDump.m | 15 |
4 files changed, 31 insertions, 7 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index 26491bf0..d291399f 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -98,6 +98,7 @@ BOOL importFieldNamesHeader; BOOL showAdvancedView; BOOL targetTableHasPrimaryKey; + NSString *primaryKeyField; NSNumber *lastDisabledCSVFieldcolumn; @@ -127,8 +128,10 @@ - (NSArray*)fieldMappingArray; - (NSArray*)fieldMappingTableColumnNames; - (NSArray*)fieldMappingGlobalValueArray; +- (NSArray*)fieldMappingTableDefaultValues; - (BOOL)importFieldNamesHeader; - (BOOL)insertRemainingRowsAfterUpdate; +- (BOOL)globalValuesInUsage; - (NSString*)onupdateString; - (NSString*)importHeaderString; diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index 9483161b..c8f2c90b 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -212,11 +212,27 @@ return fieldMappingGlobalValues; } +- (BOOL)globalValuesInUsage +{ + NSInteger i = 0; + for(id item in fieldMappingArray) { + if([item intValue] >= numberOfImportColumns && [fieldMappingOperatorArray objectAtIndex:i] != doNotImport) + return YES; + i++; + } + return NO; +} + - (NSArray*)fieldMappingTableColumnNames { return fieldMappingTableColumnNames; } +- (NSArray*)fieldMappingTableDefaultValues +{ + return fieldMappingTableDefaultValues; +} + - (BOOL)importFieldNamesHeader { return ([importFieldNamesHeaderSwitch state] == NSOnState)?YES:NO; @@ -335,7 +351,7 @@ if ([column objectForKey:@"default"]) [fieldMappingTableDefaultValues addObject:[column objectForKey:@"default"]]; else - [fieldMappingTableDefaultValues addObject:@"NULL"]; + [fieldMappingTableDefaultValues addObject:[NSNull null]]; } [fieldMappingTableTypes addObject:[NSString stringWithString:type]]; diff --git a/Source/TableDump.h b/Source/TableDump.h index 8f785f72..dc5af40f 100644 --- a/Source/TableDump.h +++ b/Source/TableDump.h @@ -106,6 +106,7 @@ typedef enum _SPExportModes { NSArray *fieldMappingTableColumnNames; NSArray *fieldMappingArray; NSArray *fieldMappingGlobalValueArray; + NSArray *fieldMappingTableDefaultValues; NSArray *fieldMapperOperator; NSString *selectedTableTarget; NSString *selectedImportMethod; @@ -113,6 +114,7 @@ typedef enum _SPExportModes { NSString *csvImportHeaderString; NSString *csvImportTailString; NSInteger fieldMapperSheetStatus; + NSInteger numberOfImportDataColumns; BOOL fieldMappingArrayHasGlobalVariables; BOOL csvImportMethodHasTail; BOOL insertRemainingRowsAfterUpdate; diff --git a/Source/TableDump.m b/Source/TableDump.m index 6657a4ee..12ab01de 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -1124,6 +1124,7 @@ if(fieldMappingArray) [fieldMappingArray release]; fieldMappingArray = nil; if(fieldMappingGlobalValueArray) [fieldMappingGlobalValueArray release]; fieldMappingGlobalValueArray = nil; if(fieldMappingTableColumnNames) [fieldMappingTableColumnNames release]; fieldMappingTableColumnNames = nil; + if(fieldMappingTableDefaultValues) [fieldMappingTableDefaultValues release]; fieldMappingTableDefaultValues = nil; if(fieldMapperOperator) [fieldMapperOperator release]; fieldMapperOperator = nil; [importPool drain]; [tableDocumentInstance setQueryMode:SPInterfaceQueryMode]; @@ -1238,6 +1239,7 @@ // Set the import array if (fieldMappingImportArray) [fieldMappingImportArray release]; fieldMappingImportArray = [[NSArray alloc] initWithArray:importData]; + numberOfImportDataColumns = [[importData objectAtIndex:0] count]; fieldMapperSheetStatus = 1; fieldMappingArrayHasGlobalVariables = NO; @@ -1268,8 +1270,10 @@ selectedImportMethod = [NSString stringWithString:[fieldMapperController selectedImportMethod]]; fieldMappingTableColumnNames = [[NSArray arrayWithArray:[fieldMapperController fieldMappingTableColumnNames]] retain]; fieldMappingGlobalValueArray = [[NSArray arrayWithArray:[fieldMapperController fieldMappingGlobalValueArray]] retain]; + fieldMappingTableDefaultValues = [[NSArray arrayWithArray:[fieldMapperController fieldMappingTableDefaultValues]] retain]; csvImportHeaderString = [[NSString stringWithString:[fieldMapperController importHeaderString]] retain]; csvImportTailString = [[NSString stringWithString:[fieldMapperController onupdateString]] retain]; + fieldMappingArrayHasGlobalVariables = [fieldMapperController globalValuesInUsage]; csvImportMethodHasTail = ([csvImportTailString length] == 0) ? NO : YES; insertRemainingRowsAfterUpdate = [fieldMapperController insertRemainingRowsAfterUpdate]; importMethodIsUpdate = ([selectedImportMethod isEqualToString:@"UPDATE"]) ? YES : NO; @@ -1286,9 +1290,6 @@ return FALSE; } - if([fieldMappingImportArray count] && [fieldMappingGlobalValueArray count] > [NSArrayObjectAtIndex(fieldMappingImportArray,0) count]) - fieldMappingArrayHasGlobalVariables = YES; - [importFieldNamesSwitch setState:[fieldMapperController importFieldNamesHeader]]; [prefs setBool:[importFieldNamesSwitch state] forKey:SPCSVImportFirstLineIsHeader]; @@ -1336,7 +1337,7 @@ [setString appendString:@"="]; // Append the data // - check for global values - if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count]) + if(fieldMappingArrayHasGlobalVariables && mapColumn >= numberOfImportDataColumns) cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn); else cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn); @@ -1356,7 +1357,7 @@ [whereString appendString:[NSArrayObjectAtIndex(fieldMappingTableColumnNames, i) backtickQuotedString]]; // Append the data // - check for global values - if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count]) + if(fieldMappingArrayHasGlobalVariables && mapColumn >= numberOfImportDataColumns) cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn); else cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn); @@ -1397,7 +1398,7 @@ // Append the data // - check for global values - if(fieldMappingArrayHasGlobalVariables && mapColumn >= [csvRowArray count]) + if(fieldMappingArrayHasGlobalVariables && mapColumn >= numberOfImportDataColumns) cellData = NSArrayObjectAtIndex(fieldMappingGlobalValueArray, mapColumn); else cellData = NSArrayObjectAtIndex(csvRowArray, mapColumn); @@ -2942,6 +2943,7 @@ fieldMappingArray = nil; fieldMappingGlobalValueArray = nil; fieldMappingTableColumnNames = nil; + fieldMappingTableDefaultValues = nil; fieldMappingImportArray = nil; csvImportTailString = nil; csvImportHeaderString = nil; @@ -2950,6 +2952,7 @@ fieldMappingArrayHasGlobalVariables = NO; importMethodIsUpdate = NO; insertRemainingRowsAfterUpdate = NO; + numberOfImportDataColumns = 0; prefs = nil; lastFilename = nil; |