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/TableDump.m | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Source/TableDump.m') 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