From 0075403979eff53d16f928733247837d72d37a0b Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 5 Mar 2010 22:37:32 +0000 Subject: =?UTF-8?q?=E2=80=A2=20CSV=20Import=20Field=20Mapper=20-=20impleme?= =?UTF-8?q?nted=20"Insert=20remaining=20rows"=20for=20import=20method=20UP?= =?UTF-8?q?DATE;=20if=20the=20UPDATE=20statement=20does't=20affect=20any?= =?UTF-8?q?=20row=20and=20this=20row=20via=20INSERT=20INTO=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPFieldMapperController.m | 1 - Source/TableDump.m | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index 5e43398c..5ed301d3 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -416,7 +416,6 @@ } } else { [advancedButton setEnabled:YES]; - [addRemainingDataSwitch setEnabled:NO]; // TODO HansJB } [self validateImportButton]; diff --git a/Source/TableDump.m b/Source/TableDump.m index 222e9715..eb07b332 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -766,6 +766,7 @@ NSMutableString *query; NSMutableString *errors = [NSMutableString string]; NSMutableString *insertBaseString = [NSMutableString string]; + NSMutableString *insertRemainingBaseString = [NSMutableString string]; NSMutableArray *parsedRows = [[NSMutableArray alloc] init]; NSMutableArray *parsePositions = [[NSMutableArray alloc] init]; NSArray *csvRowArray; @@ -1002,6 +1003,20 @@ [mySQLConnection queryString:query]; [query release]; } else { + if(insertRemainingRowsAfterUpdate) { + [insertRemainingBaseString setString:@"INSERT INTO "]; + [insertRemainingBaseString appendString:[selectedTableTarget backtickQuotedString]]; + [insertRemainingBaseString appendString:@" ("]; + insertBaseStringHasEntries = NO; + for (i = 0; i < [fieldMappingArray count]; i++) { + if ([NSArrayObjectAtIndex(fieldMapperOperator, i) integerValue] == 0) { + if (insertBaseStringHasEntries) [insertBaseString appendString:@","]; + else insertBaseStringHasEntries = YES; + [insertRemainingBaseString appendString:[NSArrayObjectAtIndex(fieldMappingTableColumnNames, i) backtickQuotedString]]; + } + } + [insertRemainingBaseString appendString:@") VALUES\n"]; + } for (i = 0; i < [parsedRows count]; i++) { if (progressCancelled) break; @@ -1021,6 +1036,25 @@ NSLocalizedString(@"[ERROR in row %ld] %@\n", @"error text when reading of csv file gave errors"), (long)(rowsImported+1),[mySQLConnection getLastErrorMessage]]]; } + + if ( insertRemainingRowsAfterUpdate && ![mySQLConnection affectedRows]) { + query = [[NSMutableString alloc] initWithString:insertRemainingBaseString]; + [query appendString:[self mappedValueStringForRowArray:[parsedRows objectAtIndex:i]]]; + + // Perform the query + if(csvImportMethodHasTail) + [mySQLConnection queryString:[NSString stringWithFormat:@"%@ %@", query, csvImportTailString]]; + else + [mySQLConnection queryString:query]; + [query release]; + + if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + [errors appendString:[NSString stringWithFormat: + NSLocalizedString(@"[ERROR in row %ld] %@\n", @"error text when reading of csv file gave errors"), + (long)(rowsImported+1),[mySQLConnection getLastErrorMessage]]]; + } + } + rowsImported++; csvRowsThisQuery++; [singleProgressBar setDoubleValue:[[parsePositions objectAtIndex:i] doubleValue]]; -- cgit v1.2.3