aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDump.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-21 21:46:10 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-21 21:46:10 +0000
commit75c1cf6b0a918752c1a6a439e96e5cf8fba7e5ea (patch)
treec0a83cb8bf543b874b9cccd407554d42ad1f1b8b /Source/TableDump.m
parent829e22e75999e9390dd6f8c0310d5171829191f0 (diff)
downloadsequelpro-75c1cf6b0a918752c1a6a439e96e5cf8fba7e5ea.tar.gz
sequelpro-75c1cf6b0a918752c1a6a439e96e5cf8fba7e5ea.tar.bz2
sequelpro-75c1cf6b0a918752c1a6a439e96e5cf8fba7e5ea.zip
• CSV Import Field Mapper
- added Advanced sheet for setting IGNORE, DELAYED, ON DUPLICATE KEY UPDATE '<string>' for INSERT/REPLACE INTO • if during import CSV Import an error occurred show SP Console
Diffstat (limited to 'Source/TableDump.m')
-rw-r--r--Source/TableDump.m26
1 files changed, 22 insertions, 4 deletions
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 077b7f4f..46bb10d2 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -953,7 +953,7 @@
[singleProgressSheet makeKeyWindow];
// Set up the field names import string for INSERT or REPLACE INTO
- [insertBaseString appendFormat:@"%@ INTO ", selectedImportMethod];
+ [insertBaseString appendFormat:@"%@", csvImportHeaderString];
[insertBaseString appendString:[selectedTableTarget backtickQuotedString]];
[insertBaseString appendString:@" ("];
insertBaseStringHasEntries = NO;
@@ -993,16 +993,26 @@
}
// Perform the query
- [mySQLConnection queryString:query];
+ if(csvImportMethodHasTail)
+ [mySQLConnection queryString:[NSString stringWithFormat:@"%@ %@", query, csvImportTailString]];
+ else
+ [mySQLConnection queryString:query];
[query release];
// If an error occurred, run the queries individually to get exact line errors
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
+ [tableDocumentInstance showConsole:nil];
for (i = 0; i < csvRowsThisQuery; i++) {
query = [[NSMutableString alloc] initWithString:insertBaseString];
[query appendString:[self mappedValueStringForRowArray:[parsedRows objectAtIndex:i]]];
- [mySQLConnection queryString:query];
+
+ // 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"),
@@ -1039,6 +1049,8 @@
[csvDataBuffer release];
[parsedRows release];
[parsePositions release];
+ if(csvImportTailString) [csvImportTailString release]; csvImportTailString = nil;
+ if(csvImportHeaderString) [csvImportHeaderString release]; csvImportHeaderString = nil;
if(fieldMappingArray) [fieldMappingArray release]; fieldMappingArray = nil;
if(fieldMappingGlobalValueArray) [fieldMappingGlobalValueArray release]; fieldMappingGlobalValueArray = nil;
if(fieldMapperOperator) [fieldMapperOperator release]; fieldMapperOperator = nil;
@@ -1184,6 +1196,9 @@
selectedImportMethod = [NSString stringWithString:[fieldMapperController selectedImportMethod]];
fieldMappingTableColumnNames = [NSArray arrayWithArray:[fieldMapperController fieldMappingTableColumnNames]];
fieldMappingGlobalValueArray = [[NSArray arrayWithArray:[fieldMapperController fieldMappingGlobalValueArray]] retain];
+ csvImportHeaderString = [[NSString stringWithString:[fieldMapperController importHeaderString]] retain];
+ csvImportTailString = [[NSString stringWithString:[fieldMapperController onupdateString]] retain];
+ csvImportMethodHasTail = ([csvImportTailString length] == 0) ? NO : YES;
if([fieldMappingImportArray count] && [fieldMappingGlobalValueArray count] > [NSArrayObjectAtIndex(fieldMappingImportArray,0) count])
fieldMappingArrayHasGlobalVariables = YES;
@@ -1433,7 +1448,7 @@
// Set up a result set in streaming mode
streamingResult = [mySQLConnection streamingQueryString:[NSString stringWithFormat:@"SELECT * FROM %@", [tableName backtickQuotedString]] useLowMemoryBlockingStreaming:([sqlFullStreamingSwitch state] == NSOnState)];
- fieldNames = [streamingResult fetchFieldNames];
+ fieldNames = [streamingResult fetchFieldNames];
// Update the progress text and set the progress bar back to determinate
[singleProgressText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Table %ld of %lu (%@): Dumping...", @"text showing that app is writing data for table dump"), (long)(i+1), (unsigned long)[selectedTables count], tableName]];
@@ -2797,6 +2812,9 @@
fieldMappingArray = nil;
fieldMappingGlobalValueArray = nil;
fieldMappingImportArray = nil;
+ csvImportTailString = nil;
+ csvImportHeaderString = nil;
+ csvImportMethodHasTail = NO;
fieldMappingImportArrayIsPreview = NO;
fieldMappingArrayHasGlobalVariables = NO;
prefs = nil;