From f4e32dd6a24793454e0af44a4429cdd9ca737724 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 22 Mar 2010 10:12:59 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20bug=20while=20CSV=20import=20-=20ca?= =?UTF-8?q?lculate=20correctly=20whether=20global=20variables=20are=20used?= =?UTF-8?q?=20or=20not=20to=20avoid=20a=20crash=20if=20the=20number=20of?= =?UTF-8?q?=20columns=20in=20the=20csv=20file=20differs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPFieldMapperController.h | 3 +++ Source/SPFieldMapperController.m | 18 +++++++++++++++++- Source/TableDump.h | 2 ++ Source/TableDump.m | 15 +++++++++------ 4 files changed, 31 insertions(+), 7 deletions(-) (limited to 'Source') 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; -- cgit v1.2.3