aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-05 22:37:32 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-05 22:37:32 +0000
commit0075403979eff53d16f928733247837d72d37a0b (patch)
tree83b7a20fbae511d2b67a323ba080a788992a01b4
parent208110e9cdaeb83737b3ba6badc6b3a8975647c9 (diff)
downloadsequelpro-0075403979eff53d16f928733247837d72d37a0b.tar.gz
sequelpro-0075403979eff53d16f928733247837d72d37a0b.tar.bz2
sequelpro-0075403979eff53d16f928733247837d72d37a0b.zip
• CSV Import Field Mapper
- implemented "Insert remaining rows" for import method UPDATE; if the UPDATE statement does't affect any row and this row via INSERT INTO…
-rw-r--r--Source/SPFieldMapperController.m1
-rw-r--r--Source/TableDump.m34
2 files changed, 34 insertions, 1 deletions
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]];